微信小程序非swiper組件實(shí)現(xiàn)的自定義偽3D輪播圖效果示例
本文實(shí)例講述了微信小程序非swiper組件實(shí)現(xiàn)的自定義偽3D輪播圖效果。分享給大家供大家參考,具體如下:
效果如下:

我用了很笨的方法實(shí)現(xiàn)的,大致就是:
1.當(dāng)前點(diǎn)擊的div(view)如果前后都有內(nèi)容,那么,當(dāng)前div(view)就設(shè)置到中間,前一個(gè)就設(shè)置到左邊,前一個(gè)的前面所有全部設(shè)置到最左邊,后面一個(gè)設(shè)置到右邊,后面所有設(shè)置到最右邊
2.當(dāng)前點(diǎn)擊的div(view)如果前面無內(nèi)容,即第一個(gè),那么,當(dāng)前div(view)設(shè)置到中間,后面一個(gè)設(shè)置到右邊,后面所有設(shè)置到最右邊
3.當(dāng)前點(diǎn)擊的div(view)如果后面無內(nèi)容,即最后一個(gè),那么,當(dāng)前div(view)設(shè)置到中間,前面一個(gè)設(shè)置到左邊,前面所有設(shè)置到最左邊
1.html
<view class='idx-content'>
<view class='idx-swiper'>
<view class='idx-cswp {{item.swpClass}}'
wx:for="{{swiperList}}" wx:key=""
bindtap="swpBtn"
data-index="{{index}}">
<image src='{{item.imgsrc}}' mode='widthFix'></image>
<view class='swp-title' hidden="{{item.swpClass!=='swp-center'}}">
<view class='swp-btime'>{{item.time}}</view>
<view class='swp-bname'>{{item.bname}}</view>
</view>
</view>
</view>
</view>
注:swp-title是標(biāo)題,用hidden替代wx:if是因?yàn)闀l繁切換。
2.wxss
.idx-content {
overflow: hidden;
padding: 0 40rpx;
}
.idx-content .idx-swiper {
position: relative;
margin: 40rpx 0;
padding-bottom: 100%;
}
.idx-content .idx-swiper .idx-cswp {
width: 70%;
height: 100%;
position: absolute;
top: 0;
border-radius: 6px;
}
.idx-content .idx-swiper .idx-cswp image {
width: 100%;
max-height: 600rpx;
}
.idx-content .idx-swiper .idx-cswp .swp-title .swp-btime {
text-align: center;
font-size: 28rpx;
}
.idx-content .idx-swiper .idx-cswp .swp-title .swp-bname {
text-align: center;
font-size: 24rpx;
}
.swp-left {/*左邊樣式*/
transition: all .3s ease;
transform: scale(0.8);
left: -55%;
}
.swp-center {/*中間樣式*/
left: 15%;
transition: all .3s ease;
transform: scale(1);
}
.swp-right {/*右邊樣式*/
transition: all .3s ease;
transform: scale(0.8);
left: 85%;
}
.swp-rightNo {/*最右邊樣式*/
transition: all .3s ease;
left: 150%;
}
.swp-leftNo {/*最左邊樣式*/
transition: all .3s ease;
left: -150%;
}
3.js
Page({
data:{
swiperList: [{//除了1,2之外,其它的swpClass都是swp-rightNo
aurl:"../start/start",
swpClass:"swp-center",
time:"2018年3月下11",
bname:"2018全球十大突破技術(shù)11",
imgsrc:"../../public/img/swiper.png"
}, {
aurl:"#",
swpClass:"swp-right",
time: "2018年3月下22",
bname: "2018全球十大突破技術(shù)22",
imgsrc: "../../public/img/swiper2.png"
}, {
aurl:"#",
swpClass:"swp-rightNo",
time: "2018年3月下33",
bname: "2018全球十大突破技術(shù)33",
imgsrc: "../../public/img/swiper3.png"
}]
},
swpBtn:function(e){
var swp = this.data.swiperList;
var max=swp.length;
var idx=e.currentTarget.dataset.index;
var prev = swp[idx-1];//前一個(gè)
var next = swp[idx+1];//后一個(gè)
var curView=swp[idx];//當(dāng)前
if (curView.swpClass ==='swp-center'){//如果當(dāng)前是在中間的,即可跳轉(zhuǎn)
wx.navigateTo({
url: curView.aurl,
})
}
if(prev){//如果當(dāng)前的前面有
if (next) {//當(dāng)前的后面有
next.swpClass = "swp-right";
}
prev.swpClass ="swp-left";
curView.swpClass = "swp-center";
for (var i =0; i < idx; i++) { //當(dāng)前前一個(gè)的前面所有
swp[i].swpClass = 'swp-leftNo'
}
}
if(next){//如果當(dāng)前的后面有
if(prev){//當(dāng)前的前面有
prev.swpClass = "swp-left";
}
curView.swpClass = "swp-center";
next.swpClass = "swp-right";
for (var i = (idx + 2); i < max; i++) {//當(dāng)前后一個(gè)的后面所有
swp[i].swpClass = 'swp-rightNo'
}
}else{
prev.swpClass = "swp-left";
curView.swpClass = "swp-center";
}
this.setData({
swiperList: swp
})
},
})
如果要實(shí)現(xiàn)滑動(dòng)切換,可用 bindtouchstart 和 bindtouchend 來實(shí)現(xiàn)。 思路大概是滑動(dòng)了一定距離之后就添加class。
還有一篇更簡單的:用swiper來實(shí)現(xiàn)的3d輪播
希望本文所述對大家微信小程序開發(fā)有所幫助。
相關(guān)文章
JavaScript使用structuredClone實(shí)現(xiàn)深拷貝
在JavaScript中,實(shí)現(xiàn)深拷貝的方式有很多種,每種方式都有其優(yōu)點(diǎn)和缺點(diǎn),今天介紹一種原生JavaScript提供的structuredClone實(shí)現(xiàn)深拷貝,文中通過代碼示例給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03
BootStrap實(shí)現(xiàn)帶有增刪改查功能的表格(DEMO詳解)
這篇文章主要介紹了BootStrap實(shí)現(xiàn)帶有增刪改查功能的表格,表格封裝了3個(gè)版本,接下來通過本文給大家展示下樣式及代碼,對bootstrap增刪改查相關(guān)知識感興趣的朋友一起通過本文學(xué)習(xí)吧2016-10-10
微信小程序?qū)崿F(xiàn)時(shí)間戳格式轉(zhuǎn)換
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)時(shí)間戳格式轉(zhuǎn)換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07
JavaScript實(shí)現(xiàn)復(fù)制圖片功能的方法示例
本文主要介紹了在JavaScript中實(shí)現(xiàn)復(fù)制圖片的方法,先介紹了實(shí)現(xiàn)復(fù)制的前置知識,包括傳統(tǒng)的 execCommand 方法及其優(yōu)缺點(diǎn)和 Clipboard API,然后詳細(xì)闡述了如何將不同形式的圖片轉(zhuǎn)化為blob對象并通過Clipboard API實(shí)現(xiàn)復(fù)制,還提及了兼容性問題及預(yù)覽、下載圖片的實(shí)現(xiàn)思路2025-03-03
關(guān)于javascript原型的修改與重寫(覆蓋)差別詳解
下面小編就為大家?guī)硪黄P(guān)于javascript原型的修改與重寫(覆蓋)差別詳解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08
javascript 拖動(dòng)表格行實(shí)現(xiàn)代碼
用js實(shí)現(xiàn)的拖動(dòng)表格的tr行的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-05-05

