您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)微信小程序如何實(shí)現(xiàn)頁面滑動(dòng)事件的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
微信小程序——頁面滑動(dòng)事件
wxml:
<view id="id" class = "ball" bindtap = "handletap" bindtouchstart = "handletouchtart" bindtouchmove="handletouchmove" bindtouchend="handletouchend" style = "width : 100%px; height : 40px;"> {{text}} </view>
wxss:
.ball { box-shadow:2px 2px 10px #AAA; border-radius: 20px; position: absolute; }
js:
//js Page({ data: { lastX: 0, //滑動(dòng)開始x軸位置 lastY: 0, //滑動(dòng)開始y軸位置 text: "沒有滑動(dòng)", currentGesture: 0, //標(biāo)識(shí)手勢 }, //滑動(dòng)移動(dòng)事件 handletouchmove: function (event) { var currentX = event.touches[0].pageX var currentY = event.touches[0].pageY var tx = currentX - this.data.lastX var ty = currentY - this.data.lastY var text = "" //左右方向滑動(dòng) if (Math.abs(tx) > Math.abs(ty)) { if (tx < 0) text = "向左滑動(dòng)" else if (tx > 0) text = "向右滑動(dòng)" } //上下方向滑動(dòng) else { if (ty < 0) text = "向上滑動(dòng)" else if (ty > 0) text = "向下滑動(dòng)" } //將當(dāng)前坐標(biāo)進(jìn)行保存以進(jìn)行下一次計(jì)算 this.data.lastX = currentX this.data.lastY = currentY this.setData({ text: text, }); }, //滑動(dòng)開始事件 handletouchtart: function (event) { this.data.lastX = event.touches[0].pageX this.data.lastY = event.touches[0].pageY }, //滑動(dòng)結(jié)束事件 handletouchend: function (event) { this.data.currentGesture = 0; this.setData({ text: "沒有滑動(dòng)", }); }, })
感謝各位的閱讀!關(guān)于“微信小程序如何實(shí)現(xiàn)頁面滑動(dòng)事件”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。