天天看點

javascript 手機手勢動作touch觸屏原理分析,h5觸摸下拉重新整理上拉加載資料原理

<!DOCTYPE>
<html> 
<head>
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="MobileOptimized" content="320"/>
<title>瑙???規??,???虹?椤?lt;/title>
<style type="text/css">
    html{-webkit-text-size-adjust:%;-ms-text-size-adjust:%;}
    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td,hr,button,article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {margin:;padding:;}
    .dragme{background:#000;width:px;height:px; color:#fff; position:absolute; left:px; top:px; text-align:center; line-height:px;}   
</style>   
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>   
<body>   
<div id="moveid" class="dragme"> 
    lvtao.net
</div> 
<script type="text/javascript"> 
var isdrag=false;   
var tx,x,ty,y;    
$(function(){   
    document.getElementById("moveid").addEventListener('touchstart',touchStart);  
    document.getElementById("moveid").addEventListener('touchmove',touchMove);
    document.getElementById("moveid").addEventListener('touchend',function(){  
        isdrag = false;  
    }); 
});
function touchStart(e){   
   isdrag = true; 
   e.preventDefault();
   tx = parseInt($("#moveid").css('left'));    
   ty = parseInt($("#moveid").css('top'));  
   x = e.touches[].pageX;
   y = e.touches[].pageY;  
}   
function touchMove(e){   
  if (isdrag){
   e.preventDefault();
       var n = tx + e.touches[].pageX - x;
       var h = ty + e.touches[].pageY - y;   
       $("#moveid").css("left",n); 
       $("#moveid").css("top",h);    
   }  
}    
</script> 
</body>
</html>
           

繼續閱讀