我是棱角分明的新手,我想制作像这样在中心有活动项目的旋转木马:
我已阅读slick carousel for angular 2 or higher
我试图复制example,我已按照说明操作,但收到此错误:
ERROR 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"
],
这是我的模块:
...
import { SlickModule } from 'ngx-slick';
import { SliderComponent } from './home/slider/slider.component';
@NgModule({
declarations: [
... ,
SliderComponent,
],
imports: [
... ,
SlickModule.forRoot()
],
providers: [...],
bootstrap: [AppComponent]
})
export class AppModule { }
这是我的观点:
<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>
这是我的组成部分:
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);
}
}
这是关于打字稿中使用的jquery吗? 或者也许给我一些旋转木马的参考,就像我制作的 lul pic 一样。
答案 0 :(得分:4)
将slideConfig替换为以下代码:
slideConfig = {
"slidesToShow": 1,
"slidesToScroll": 1,
"dots": true,
"infinite": true,
"autoplay": true,
"autoplaySpeed": 1500
};
答案 1 :(得分:0)
.timelineSliderNav .slick-slide p {
position: absolute;
bottom: -10px;
}
你必须移动到index.html的lib脚本。
在 <script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/slick-carousel@1.6.0/slick/slick.js"></script>
中,它不起作用:(
答案 2 :(得分:0)
我尝试了一下,并使其正常运行,将其位置移至index.html,它将正常工作。
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/slick-carousel@1.6.0/slick/slick.js"></script>