欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 監(jiān)聽(tīng)手勢(shì)滑動(dòng)切換頁(yè)面實(shí)例詳解

 更新時(shí)間:2017年06月15日 15:23:35   投稿:lqh  
這篇文章主要介紹了微信小程序 監(jiān)聽(tīng)手勢(shì)滑動(dòng)切換頁(yè)面實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

微信小程序 監(jiān)聽(tīng)手勢(shì)滑動(dòng)切換頁(yè)面實(shí)例詳解

1.對(duì)應(yīng)的xml里寫上手勢(shì)開(kāi)始、滑動(dòng)、結(jié)束的監(jiān)聽(tīng):

<view class="touch" bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd" ></view> 

2.js:

var touchDot = 0;//觸摸時(shí)的原點(diǎn) 
var time = 0;// 時(shí)間記錄,用于滑動(dòng)時(shí)且時(shí)間小于1s則執(zhí)行左右滑動(dòng) 
var interval = "";// 記錄/清理時(shí)間記錄 
Page({ 
 data: {...} 
   }) 
Page({ 
 data: { 
     ... 
 }, 
 // 觸摸開(kāi)始事件 
 touchStart: function (e) { 
  touchDot = e.touches[0].pageX; // 獲取觸摸時(shí)的原點(diǎn) 
  // 使用js計(jì)時(shí)器記錄時(shí)間  
  interval = setInterval(function () { 
   time++; 
  }, 100); 
 }, 
 // 觸摸移動(dòng)事件 
 touchMove: function (e) { 
  var touchMove = e.touches[0].pageX; 
  console.log("touchMove:" + touchMove + " touchDot:" + touchDot + " diff:" + (touchMove - touchDot)); 
  // 向左滑動(dòng)  
  if (touchMove - touchDot <= -40 && time < 10) { 
   wx.switchTab({ 
    url: '../左滑頁(yè)面/左滑頁(yè)面' 
   });  
  } 
  // 向右滑動(dòng) 
  if (touchMove - touchDot >= 40 && time < 10) { 
   console.log('向右滑動(dòng)'); 
   wx.switchTab({ 
    url: '../右滑頁(yè)面/右滑頁(yè)面' 
   });  
  } 
 }, 
 // 觸摸結(jié)束事件 
 touchEnd: function (e) { 
  clearInterval(interval); // 清除setInterval 
  time = 0; 
 }, 
. 
. 
. 
}) 

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論