最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

小程序?qū)崿F(xiàn)層疊卡片滑動(dòng)效果

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 21:51:55
文檔

小程序?qū)崿F(xiàn)層疊卡片滑動(dòng)效果

小程序?qū)崿F(xiàn)層疊卡片滑動(dòng)效果:小程序?qū)盈B卡片滑動(dòng)效果,供大家參考,具體內(nèi)容如下 效果圖 wxml <!-- 輪播wxml代碼 --> <view class=teachers_banner> <view class=lunbo_center clearfix teachers_b> <view clas
推薦度:
導(dǎo)讀小程序?qū)崿F(xiàn)層疊卡片滑動(dòng)效果:小程序?qū)盈B卡片滑動(dòng)效果,供大家參考,具體內(nèi)容如下 效果圖 wxml <!-- 輪播wxml代碼 --> <view class=teachers_banner> <view class=lunbo_center clearfix teachers_b> <view clas

小程序?qū)盈B卡片滑動(dòng)效果,供大家參考,具體內(nèi)容如下

效果圖

wxml

<!-- 輪播wxml代碼 -->
<view class="teachers_banner">
 <view class="lunbo_center clearfix teachers_b">
 <view class="slide" id="slide" bindtouchstart='moveStart' bindtouchend='moveItem'>
 <ul>
 <block wx:for="{{datas}}" wx:key>
 <li animation="{{item.animation}}" style="z-index: {{item.zIndex}} ;opacity:{{item.opacity}};"
 bindtap="choose" data-id="{{item.id}}">
 <image src="{{item.iamge}}" />
 </li>
 </block>
 </ul>
 </view>
 </view>
</view>

wxss

/*輪播圖片*/
.lunbo_center {
 display: flex;
 flex-direction: column;
 align-items: center;
 justify-content: space-between;
 padding: 50rpx 0;
 box-sizing: border-box;
}
.teachers_b {
 position: relative;
}
#slide {
 margin: 0 auto;
 width: 100%;
 height: 160px;
 position: relative;
}
#slide li {
 position: absolute;
 width: 600rpx;
 height: 300rpx;
 display: -webkit-box;
 display: -webkit-flex;
 display: flex;
 align-items: flex-start;
 -webkit-box-align: flex-start;
 -webkit-align-items: flex-start;
 background: #fff;
 overflow: hidden;
 box-shadow: 0 0 20px #1d374d;
}
#slide li image {
 width: 100%;
 height: 100%;
}
.slide_left {
 width: 240px;
}
.slide_right {
 padding: 40px;
 -webkit-box-flex: 1;
 -webkit-flex: 1;
 flex: 1;
 min-width: 0;
}
.slide_right h3 {
 font: 400 30px/18px "Microsoft Yahei";
 color: #222;
}
.slide_right h3 span {
 display: inline-block;
 margin-left: 10px;
 font: 400 14px/36px "Microsoft Yahei";
 color: #555;
}
.slide_right p {
 padding: 20px 0 30px;
 color: #555;
 font: 400 14px/24px "Microsoft Yahei";
 border-bottom: 1px solid #dbdbdb;
}
.slide_right dl {
 padding-top: 30px;
}
.slide_right dd {
 /* float: left; */
 width: 33.3%;
 color: #777;
 font: 400 12px/24px "Microsoft Yahei";
}
.slide_right dd h3 {
 color: #ff9000;
 margin-bottom: 20px;
}
.arrow {
 display: none;
}
.arrow .prev, .arrow .next {
 position: absolute;
 width: 64px;
 top: 38%;
 z-index: 9;
 font: 700 96px 'simsun';
 opacity: 0.3;
 color: #fff;
 cursor: pointer;
}
.arrow .prev {
 left: -220px;
}
.arrow .next {
 right: -220px;
}
.arrow .prev:hover, .arrow .next:hover {
 color: #00a0e9;
 opacity: 0.7;
}

js

// js代碼
Page({
 /**
 * 頁(yè)面的初始數(shù)據(jù)
 */
 data: {
 startX: 0,
 endX: 0,
 iCenter: 3,
 datas: [{
 id: 1,
 zIndex: 2,
 opacity: 0.2,
 left: 10,
 iamge: "../../icon/lunbo2.jpg",
 animation: null
 },
 {
 id: 2,
 zIndex: 4,
 opacity: 0.4,
 left: 20,
 iamge: "../../icon/lunbo3.jpg",
 animation: null
 },
 {
 id: 3,
 zIndex: 6,
 opacity: 0.6,
 left: 30,
 iamge: "../../icon/lunbo4.jpg",
 animation: null
 },
 {
 id: 4,
 zIndex: 8,
 opacity: 1,
 left: 40,
 iamge: "../../icon/lunbo1.jpg",
 animation: null
 },
 {
 id: 5,
 zIndex: 6,
 opacity: 0.6,
 left: 50,
 iamge: "../../icon/lunbo2.jpg",
 animation: null
 },
 {
 id: 6,
 zIndex: 4,
 opacity: 0.4,
 left: 60,
 iamge: "../../icon/lunbo3.jpg",
 animation: null
 } ,
 {
 id: 7,
 zIndex: 2,
 opacity: 0.2,
 left: 70,
 iamge: "../../icon/lunbo1.jpg",
 animation: null
 }
 ],
 order: []
 },
 /**
 * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
 */
 onLoad: function (options) {
 this.__set__();
 this.move();
 },
 move: function () {
 var datas = this.data.datas;
 /*圖片分布*/
 for (var i = 0; i < datas.length; i++) {
 var data = datas[i];
 var animation = wx.createAnimation({
 duration: 100
 });
 animation.translateX(data.left).step();
 this.setData({
 ["datas[" + i + "].animation"]: animation.export(),
 ["datas[" + i + "].zIndex"]: data.zIndex,
 ["datas[" + i + "].opacity"]: data.opacity,
 })
 }
 },
 /**左箭頭 */
 left: function () {
 //
 var last = this.data.datas.pop(); //獲取數(shù)組的最后一個(gè)
 this.data.datas.unshift(last);//放到數(shù)組的第一個(gè)
 var orderFirst = this.data.order.shift();
 this.data.order.push(orderFirst);
 this.move();
 },
 /** */
 right: function () {
 var first = this.data.datas.shift(); //獲取數(shù)組的第一個(gè)
 this.data.datas.push(first);//放到數(shù)組的最后一個(gè)位置
 var orderLast = this.data.order.pop();
 this.data.order.unshift(orderLast);
 this.move();
 },
 /**點(diǎn)擊某項(xiàng) */
 choose: function (e) {
 var that = this;
 var id = e.currentTarget.dataset.id;
 var order = that.data.order;
 var index = 0;
 for (var i = 0; i < order.length; i++) {
 if (id == order[i]) {
 index = i;
 break;
 }
 }
 if (index < that.data.iCenter) {
 for (var i = 0; i < that.data.iCenter - index; i++) {
 this.data.datas.push(this.data.datas.shift()); //獲取第一個(gè)放到最后一個(gè)
 this.data.order.unshift(this.data.order.pop());
 // this.right() 
 }
 } else if (index > that.data.iCenter) {
 for (var i = 0; i < index - that.data.iCenter; i++) {
 this.data.datas.unshift(this.data.datas.pop()); //獲取最后一個(gè)放到第一個(gè)
 this.data.order.push(this.data.order.shift());
 // this.left();
 }
 }
 this.move();
 },
 /**新的排列復(fù)制到新的數(shù)組中 */
 __set__: function () {
 var that = this;
 var order = that.data.order;
 var datas = that.data.datas;
 for (var i = 0; i < datas.length; i++) {
 that.setData({
 ["order[" + i + "]"]: datas[i].id
 })
 }
 },
 //手指觸發(fā)開(kāi)始移動(dòng)
 moveStart: function (e) {
 console.log(e);
 var startX = e.changedTouches[0].pageX;
 this.setData({
 startX: startX
 });
 },
 //手指觸摸后移動(dòng)完成觸發(fā)事件
 moveItem: function (e) {
 console.log(e);
 var that = this;
 var endX = e.changedTouches[0].pageX;
 this.setData({
 endX: endX
 });
 //計(jì)算手指觸摸偏移劇距離
 var moveX = this.data.startX - this.data.endX;
 //向左移動(dòng)
 if (moveX > 20) {
 this.left();
 }
 if (moveX < -20) {
 this.right();
 }
 },
})

歡迎參考!

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

小程序?qū)崿F(xiàn)層疊卡片滑動(dòng)效果

小程序?qū)崿F(xiàn)層疊卡片滑動(dòng)效果:小程序?qū)盈B卡片滑動(dòng)效果,供大家參考,具體內(nèi)容如下 效果圖 wxml <!-- 輪播wxml代碼 --> <view class=teachers_banner> <view class=lunbo_center clearfix teachers_b> <view clas
推薦度:
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top