小程序实现自动轮播图效果————(2020.1.3学习笔记)

微信小程序自带轮播图的组件,所以直接调用(代码如下)

<swiper class="swiper"
   circular="true"
   autoplay="true"
   interval="3000"
   duration="300"
   indicator-dots="true"
   indicator-active-color="#ff577">
<block wx:for="{{banners}}" wx:key="{{index}}">
<swiper-item class="swiper-item">
<image src="{{item.image}}" mode="widthFix"/>

</swiper-item>
</block>
</swiper>

其中swiper的circular属性,决定是否采用衔接滑动,autoplay属性决定是否自动轮播,interval属性决定自动切换时间间隔,duration属性决定滑动动画时长,indicator-dots和indicator-active-color属性决定是否显示面板指示点和指示点颜色。

然后轮播图没数据是没办法显示图片的,所以第二步就是获取数据,但因为这里没服务器,所以这里直接在本地声明所需数据(代码如下)

  data: {
       banners:[
        {image:'https://i0.hdslb.com/bfs/archive/7cbb50f72bbac972e8ba760c1ca01ab31906b624.jpg@1100w_484h_1c_100q.jpg'},
        {image:'https://i0.hdslb.com/bfs/archive/cd8c899fa02738edd84221e8d7e82dc1caf7ba81.jpg@1100w_484h_1c_100q.jpg'},
        {image:'https://i0.hdslb.com/bfs/archive/d444caba56094cd3036e7fef4c211f279784c8fd.jpg@1100w_484h_1c_100q.jpg'},
        {image:'https://i0.hdslb.com/bfs/sycp/creative_img/202001/069f736ee91daac0ce588fe62d4d7289.jpg@1100w_484h_1c_100q.jpg'},

       ],
     
  },

最后预览的效果如下图
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值