首頁  >  文章  >  web前端  >  H5上滑跳轉頁面的實作(程式碼實例)

H5上滑跳轉頁面的實作(程式碼實例)

青灯夜游
青灯夜游轉載
2018-10-11 17:18:424284瀏覽

本文介紹H5上滑跳轉頁面的實現,有一定的參考價值,有需要的朋友可以參考一下,希望對你們有幫助。

方法一:

jquery方法

movePage($('body'));
   function movePage(dom) {
       var startY, moveY, moveSpave;
       dom.on("touchstart", function(e) {
               startY = e.originalEvent.touches[0].pageY; return startY;
        });
        dom.on("touchmove", function(e) {
              moveY = e.originalEvent.touches[0].pageY;
              moveSpave = startY - moveY;
              if (moveSpave > 15) {
                   location.href = 'main.html';              /* 跳转到main.html */
               }
        });
  }

方法二:

原生方法  

     var strat,move,num; /*定义三个变量, 记录开始、结束距离顶部的距离*/
     p_demo.addEventListener("touchstart", function (e){        /*触摸开始*/
            console.log("触摸开始")
            // console.log(e)
            start = e.touches[0].pageY;
            console.log(start)       /*得出刚触屏时距离页面顶部的距离*/
      })
     p_demo.addEventListener("touchmove", function (e){       /*触摸移动*/
            console.log("触摸移动")
            // console.log(e)
            move = e.touches[0].pageY;
            console.log(move)     /*得出触屏结束后距离页面顶部的距离*/
    }) 
   p_demo.addEventListener("touchend", function (e){            /*触摸结束*/
            console.log("触摸结束")
            // console.log(e)
            num = start - move ;   /*得出开始和结束距离页面顶部的差值*/
            if(num>15){
                 location.href="main.html"           /* 跳转到main.html */
            }
    })

總結:以上是這篇文章的全部內容,希望對大家的學習有所幫助。更多相關教學請造訪Html5影片教學jQuery影片教學

相關推薦:

php公益訓練影片教學

#HTML5圖文教學

HTML5線上手冊

html5特效程式碼大全

#

以上是H5上滑跳轉頁面的實作(程式碼實例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:cnblogs.com。如有侵權,請聯絡admin@php.cn刪除