微信小程序> 微信小程序实现轮播图

微信小程序实现轮播图

浏览量:435 时间: 来源:我不淑女girl

微信小程序轮播图要用到swiper组件,即滑块视图容器
wxml代码

<view>  <swiper   autoplay='true'   current="{{swiperCurrent}}"  interval='5000'  duration='200'  bindchange='swiperChange'  circular='true'  >  <!--   autoplay 为布尔值,默认为false,是否自动切换  current 为数字类型,默认为0,  当前所在滑块的 index   interval 数字类型,默认为5000,自动切换时间间隔  duration 数字类型,默认500,滑动动画时长  circular 为布尔值,默认为false,是否采用衔接滑动   -->    <block wx:for='{{list}}' wx:key='{{list}}'>      <swiper-item>        <image src='{{item.urlImg}}'></image>      </swiper-item>    </block>  </swiper>  <view class='content'>    <block wx:for='{{list}}' wx:key='{{list}}'>      <image  src='{{item.urlImg}}' data-i='{{index}}' bindtap='move' class="imgStyle{{index == Imgcurrent ? 'select' : ''}}"></image>    </block>  </view></view>

wxss代码

.content {  display: flex;  justify-content: center;}.imgStyle {  width: 120rpx;  height: 80rpx;  border:1px solid red;  margin: 4rpx;  margin-top: 8rpx;  transition: all 0.6s;}

js代码

Page({  data: {    list: [{        urlImg: '../../img/1.png'      },      {        urlImg: '../../img/2.png'      },      {        urlImg: '../../img/3.png'      },      {        urlImg: '../../img/4.png'      },      {        urlImg: '../../img/5.png'      },    ],    swiperCurrent: 0,    windowWidth: wx.getSystemInfoSync().windowWidth  },  move: function(e) {    // console.log(e)    this.setData({      swiperCurrent: e.currentTarget.dataset.i    })  },  swiperChange: function(e) {    // console.log(e)    this.setData({      swiperCurrent: e.detail.current    })  }})
微信小程序

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎