touchstart ,touchmove, touchend 页面随手指滑动
来源:互联网 发布:联动mpos 机报件软件 编辑:程序博客网 时间:2024/06/05 11:07
<pre style="font-family: 'Courier New'; background-color: rgb(255, 255, 255);"><span style="font-size:32px;">js写法</span>
</pre><pre code_snippet_id="1717282" snippet_file_name="blog_20160615_3_9095677" name="code" class="html">
//详情页滑出效果function swipePage(){//页面滑动切换效果 //$("#goodsdetil").animate({right:-(e.pageX)}/*,400,function(){$("#goodsMealDiv").empty();}*/); //$('body').css("overflow","hidden"); $('body').on('touchmove', function (event) {//禁止浏览器上下滑动 event.preventDefault(); }); var startX, startY, endX, endY; var showADID = 1; document.getElementById("goodsdetil").addEventListener("touchstart", touchStart, false); document.getElementById("goodsdetil").addEventListener("touchmove", touchMove, false); document.getElementById("goodsdetil").addEventListener("touchend", touchEnd, false); function touchStart(event) { var touch = event.touches[0]; startY = touch.pageY; startX = touch.pageX; } function touchMove(event) { var touch = event.touches[0]; endX = touch.pageX; //console.log("X轴移动大小:" + (startX - endX)); if((startX - endX)<0){ $("#goodsdetil").animate({right:(startX - endX)},0); } } function touchEnd(event) { if((startX - endX)>-300){ $("#goodsdetil").animate({right:"0px"},300); }else if((startX - endX)<-300){ pageHide(); } }}
jQuery 写法
function swipePage(){//页面滑动切换效果 //$("#goodsdetil").animate({right:-(e.pageX)}/*,400,function(){$("#goodsMealDiv").empty();}*/); //$('body').css("overflow","hidden"); $('body').on('touchmove', function (event) {//禁止浏览器上下滑动 event.preventDefault(); }); var startX, startY, endX, endY; $("#goodsdetil").bind("touchstart", touchStart); $("#goodsdetil").bind("touchmove", touchMove); $("#goodsdetil").bind("touchend", touchEnd); function touchStart(event) { var touch = event.originalEvent.targetTouches[0]; startY = touch.pageY; startX = touch.pageX; } function touchMove(event) { var touch = event.originalEvent.targetTouches[0]; endX = touch.pageX; //console.log("X轴移动大小:" + (startX - endX)); if((startX - endX)<0){ $("#goodsdetil").animate({right:(startX - endX)},0); } } function touchEnd(event) { if((startX - endX)>-300){ $("#goodsdetil").animate({right:"0px"},300); }else if((startX - endX)<-300){ pageHide(); } }}
0 0
- touchstart ,touchmove, touchend 页面随手指滑动
- H5 touchstart、touchmove、touchend 拖拽
- 触摸三事件touchstart,touchend,touchmove
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- jQuery touchstart,touchmove,touchend 获取位置
- 【HTML5】触摸事件(touchstart、touchmove和touchend)
- 触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- h5触摸事件:touchstart、touchmove和touchend
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- Linux日志文件系统及性能分析
- Android最全的屏幕适配
- CSS选择器
- 从 React Router 谈谈路由的那些事
- Mac 中显示资源库(Library)文件夹目录的几种方法
- touchstart ,touchmove, touchend 页面随手指滑动
- get请求
- online-simulator-in-linux-practice-linux-commands
- 昨天学到的使用SSM框架时从mysql中查到数据并展示出来的的两个下拉框
- Ubuntu 安装 gcc/g++ 5.0
- React服务器端渲染
- 学习之路之错误笔记day06之盒子模型及session
- JavaScript学习笔记八:函数定义和调用
- iOS开发零基础教程之真机调试流程