微信小程序之視圖容器(swiper)組件創建輪播圖
阿新 • • 發佈:2018-08-31
lis center width png slide 滑動動畫 -a indicator navigator
一、視圖容器(Swiper)
1、swiper:滑塊視圖容器
微信官方文檔:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html
二、swiper應用
1、頁面邏輯(index.js)
Page({
data: {
imgUrls: [
{
link: ‘/pages/index/index‘,
url: ‘/images/001.jpg‘
}, {
link: ‘/pages/list/list‘,
url: ‘/images/002.jpg‘
}, {
link: ‘/pages/list/list‘,
url: ‘/images/003.jpg‘
}
],
indicatorDots: true, //小點
indicatorColor: "white",//指示點顏色
activeColor: "coral",//當前選中的指示點顏色
autoplay: false, //是否自動輪播
interval: 3000, //間隔時間
duration: 3000, //滑動時間
}
其中 imgUrls 是我們輪播圖中將要用到的 圖片地址和 跳轉鏈接
indicatgorDots 是否出現焦點
autoplay 是否自動播放
interval 自動播放間隔時間
duration 滑動動畫時間
2、頁面結構(index.wxml)
<!--輪播圖-->
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" indicator-color="{{indicatorColor}}"
indicator-active-color ="{{activeColor}}">
<block wx:for="{{imgUrls}}">
<swiper-item>
<navigator url="{{item.link}}" hover-class="navigator-hover">
<image src="{{item.url}}" class="slide-image" width="355" height="200" />
</navigator>
</swiper-item>
</block>
</swiper>
註意: swiper 千萬不要在外面 加上任何標簽 例如 <view> 之類的 ,如果加了可能會導致輪播圖出不來
3、頁面樣式(index.wxss)
/*輪播圖*/
.slide-image {
width: 100%;
}
三、小程序效果圖
趕快動手實踐就可以看到如圖所示效果圖:
微信小程序之視圖容器(swiper)組件創建輪播圖