Arz*_*rza 0 carousel typescript slick angular
我是新手,我想制作这样的旋转木马,其中央有活动项,如下所示:

我已经读过角度为2或更高的光滑轮播
我尝试复制该示例,并按照说明进行操作,但出现此错误:
错误TypeError:$(...)。slick不是函数
app.module我已经添加了CSS和JS angular-cli.json
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"theme.scss",
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/slick-carousel/slick/slick.css",
"../node_modules/slick-carousel/slick/slick-theme.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js",
"../node_modules/slick-carousel/slick/slick.js"
],
Run Code Online (Sandbox Code Playgroud)这是我的模块:
...
import { SlickModule } from 'ngx-slick';
import { SliderComponent } from './home/slider/slider.component';
@NgModule({
declarations: [
... ,
SliderComponent,
],
imports: [
... ,
SlickModule.forRoot()
],
providers: [...],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
这是我的看法:
<h2>slider here </h2>
<ngx-slick class="carousel" #slickModal="slick-modal" [config]="slideConfig"
(afterChange)="afterChange($event)">
<div ngxSlickItem *ngFor="let slide of slides" class="slide">
<img src="{{ slide.img }}" alt="" width="100%">
</div>
</ngx-slick>
<button (click)="addSlide()">Add</button>
<button (click)="removeSlide()">Remove</button>
<button (click)="slickModal.slickGoTo(2)">slickGoto 2</button>
<button (click)="slickModal.unslick()">unslick</button>
Run Code Online (Sandbox Code Playgroud)
这是我的组件:
import { Component, OnInit } from '@angular/core';
import { EventEmitter } from '@angular/core';
@Component({
selector: 'app-slider',
templateUrl: './slider.component.html',
styleUrls: ['./slider.component.css']
})
export class SliderComponent implements OnInit {
constructor() { }
ngOnInit() {
}
slides = [
{ img: 'http://placehold.it/350x150/000000' },
{ img: 'http://placehold.it/350x150/111111' },
{ img: 'http://placehold.it/350x150/222222' },
{ img: 'http://placehold.it/350x150/333333' },
{ img: 'http://placehold.it/350x150/444444' },
{ img: 'http://placehold.it/350x150/555555' }
];
slideConfig = { 'slidesToShow': 4, 'slidesToScroll': 4 };
addSlide() {
this.slides.push({ img: 'http://placehold.it/350x150/666666' })
}
removeSlide() {
this.slides.length = this.slides.length - 1;
}
afterChange(e) {
console.log('afterChange', e);
}
}
Run Code Online (Sandbox Code Playgroud)
这是关于打字稿中使用的jQuery的吗?
或像我制作的lul图片一样,给我一些有关轮播的参考。
将您的slideConfig替换为以下代码:
slideConfig = {
"slidesToShow": 1,
"slidesToScroll": 1,
"dots": true,
"infinite": true,
"autoplay": true,
"autoplaySpeed": 1500
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8355 次 |
| 最近记录: |