angular2 使用swiper

JenK

第一步:

npm install swiper --save

第二步:下载swiper ts支持(ts声明文件:http://microsoft.github.io/Ty...)

npm install  @types/swiper --save

ts文件里:

import swiper from "Swiper";

swiperSlide:any
  swiperw() {
    let ss = new swiper('.swiper-container', {
      loop: true, // 循环模式选项
      effect : 'flip',
     //  effect: 'cube'
    })
    this.swiperSlide = ss
  }
  goto(e) {
    this.swiperSlide.slideToLoop(e, 1000, false);//切换到第一个slide,速度为1秒
  }

html

<div class="swiper-container swiper-no-swiping">
  <div class="swiper-wrapper">
      <div class="swiper-slide" style="background:red" (click)="goto(1)">Slide 1</div>
      <div class="swiper-slide" style="background:blue">Slide 2</div>
  </div>
</div>
<button (click)="goto(1)" >1111111</button>
<button (click)="goto(0)" >222222</button>

css

.swiper-container {
    width: 600px;
    height: 300px;
}

阅读 1.3k
avatar
JenK
北京中电兴发 前端工程师

理想的光芒很难照进现实

8.7k 声望
7k 粉丝
0 条评论
你知道吗?

avatar
JenK
北京中电兴发 前端工程师

理想的光芒很难照进现实

8.7k 声望
7k 粉丝
文章目录
宣传栏