网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序 監聽手勢滑動切換頁面

發布時間:2017-12-19 10:22 所屬欄目:小程序開發教程

1.對應的xml里寫上手勢開始、滑動、結束的監聽:view class="touch" bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd" /view2.js: view plain copyvar touchDot = 0;//觸摸時的原點 ...

 
 
 

1.對應的xml里寫上手勢開始、滑動、結束的監聽:

 

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

2.js:

 

		
  1. [javascript] view plain copy
  2. var touchDot = 0;//觸摸時的原點
  3. var time = 0;// 時間記錄,用于滑動時且時間小于1s則執行左右滑動
  4. var interval = "";// 記錄/清理時間記錄
  5. Page({
  6. data: {...}
  7. })
 

		
  1. Page({
  2. data: {
  3. ...
  4. },
  5. // 觸摸開始事件
  6. touchStart: function (e) {
  7. touchDot = e.touches[0].pageX; // 獲取觸摸時的原點
  8. // 使用js計時器記錄時間
  9. interval = setInterval(function () {
  10. time++;
  11. }, 100);
  12. },
  13. // 觸摸移動事件
  14. touchMove: function (e) {
  15. var touchMove = e.touches[0].pageX;
  16. console.log("touchMove:" + touchMove + " touchDot:" + touchDot + " diff:" + (touchMove - touchDot));
  17. // 向左滑動
  18. if (touchMove - touchDot <= -40 && time < 10) {
  19. wx.switchTab({
  20. url: '../左滑頁面/左滑頁面'
  21. });
  22. }
  23. // 向右滑動
  24. if (touchMove - touchDot >= 40 && time < 10) {
  25. console.log('向右滑動');
  26. wx.switchTab({
  27. url: '../右滑頁面/右滑頁面'
  28. });
  29. }
  30. },
  31. // 觸摸結束事件
  32. touchEnd: function (e) {
  33. clearInterval(interval); // 清除setInterval
  34. time = 0;
  35. },
  36. .
  37. .
  38. .
  39. })


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/18200.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×