H5上滑跳转页面的实现(代码实例)


本文摘自PHP中文网,作者青灯夜游,侵删。

本文给大家介绍H5上滑跳转页面的实现,有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。

方法一:

jquery方法

1

2

3

4

5

6

7

8

9

10

11

12

13

14

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 */

               }

        });

  }

方法二:

原生方法

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

  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上滑跳转页面的实现(代码实例)的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

html5中在用户可以开始播放视频/音频时触发的事件oncanplay

html5规定元素是否可拖动的属性draggable

几个很好用的html5移动开发框架

什么是html5?html5使用详解

详细介绍html5中的新事件

使用html5捕捉音频与视频信息概述及实例

html5的video标签操作视频详解

浅谈html5和html4之间的不同

html5制作查询页面实例

深入了解h5中history特性--pushstate、replacestate

更多相关阅读请进入《h5》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...