html5 touch事件实现触屏页面上下滑动(二)
var touch=e.touches[0]; startY = touch.pageY; //刚触摸时的坐标 }
function touchMove(e){//滑动 e.preventDefault(); var touch = e.touches[0]; y = touch.pageY - startY;//滑动的距离 inner.style.top=aboveY+y+"px"; document.getElementById("spText").innerHTML=inner.style.top;
}
function touchEnd(e){//手指离开屏幕 aboveY=parseInt(inner.style.top);//touch结束后记录内部滑块滑动的位置 在全局变量中体现 一定要用parseInt()将其转化为整数字; if(y>0&>0){//当滑动到最顶端时候不能再网上滑动 //inner.style.top=0; $("#inner").animate({top:0},200); aboveY=0; }
if(y<0&&(aboveY<(-(documentHeight-wapperHeight)))){//当滑动到最底部时候不能再网下滑动 (编辑:焦作站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |