作者:默識,來自原文地址功能描述
演示
文件介紹
hSwiper.js //插件的核心文件
hSwiper.wxml //插件的dom結(jié)構(gòu)
hSwiper.wxss //插件的css
hSwiperTemplate.wxml //插件每個元素的模版
使用方法下載本插件,在需要使用的page的相關(guān)位置導(dǎo)入對應(yīng)的hSwiper.js,hSwiper.wxss以及hSwiper.wxml即可,具體使用如下 index.js
const hSwiper=require("../../component/hSwiper/hSwiper.js");
var option={
data:{
//swiper插件變量
hSwiperVar:{}
},
onLoad:function(){
},
onReady:function(){
//實例化插件
var swiper=new hSwiper({reduceDistance:60,varStr:"hSwiperVar",list:[1,2,3,4,5]});
swiper.onFirstView=function(data,index){
console.log("當前是第"+(index+1)+"視圖","數(shù)據(jù)是:"+data);
};
swiper.onLastView=function(data,index){
console.log("當前是第"+(index+1)+"視圖","數(shù)據(jù)是:"+data);
};
swiper.afterViewChange=function(data,index){
console.log("當前是第"+(index+1)+"視圖","數(shù)據(jù)是:"+data);
};
swiper.beforeViewChange=function(data,index){
console.log("當前是第"+(index+1)+"視圖","數(shù)據(jù)是:"+data);
};
//更新數(shù)據(jù)
setTimeout(()=>{
console.log("3 s 后更新列表數(shù)據(jù)");
//3 s 后更新列表數(shù)據(jù)
this.setData({
"hSwiperVar.list[0]":"修改"
});
}, 3000);
setTimeout(()=>{
console.log("5s后更新數(shù)據(jù) 并且更新視圖");
//5s后更新數(shù)據(jù) 并且更新視圖
var oldList=swiper.getList();
swiper.updateList(oldList.concat([11,23,45]));
}, 5000);
}
};
Page(option);
index.wxml
<import src="../../component/hSwiper/hSwiper.wxml"/>
<view id="mainContainer">
<template is="hSwiper" data="{{...hSwiperVar}}"></template>
</view>
index.wxss
@import "../../component/hSwiper/hSwiper.wxss";
/*滾動圖*/
#mainContainer{
height: 100%;
width: 100%;
}
.itemSelf{
height: 100%;
position: absolute;
box-sizing:border-box;
margin:10rpx;
overflow: hidden;
padding: 10rpx;
box-shadow: 0 0 1px 1px rgba(0,0,0,0.1);
height: 95%;
width: 96%;
background-color: gray;
color: white;
}
hSwiperTemplate.wxml (hswiper視圖元素模版)每個視圖的內(nèi)容的wxml都寫在該文件里面,使用 template標簽 ,并且命名 ,當調(diào)用這里面的模版時,會自動注入 item以及 index數(shù)據(jù),index表示是當前元素的元素索引 ,item則表示當前元素 數(shù)據(jù)。(相當于list[index]=item,但是 list不會注入到模版里面)
<template name="hSwiperItem">
<view class="itemSelf">
{{item}}
</view>
</template>
<template name="templateb">
{{item}}
</template>
hSwiper入口參數(shù)解釋
var swiper=new hSwiper({
reduceDistance:60,
varStr:"hSwiperVar",
list:[1,2,3,4,5]
});
接口
事件item,index為當前視圖的數(shù)據(jù),以及索引
具體使用 可查看example文件夾下的例子,有注釋說明。歡迎提問!??!
github地址:https://github.com/hlerenow/hSwiper
|