We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>判断滑动方向</title> </head> <style> html{ height: 100%; } body{ height: 100%; background-color: #f47500; } </style> <body> </body> <script> var touchStartClientX,touchStartClientY, direction; document.addEventListener('touchstart',function(e){ touchStartClientX= e.touches[0].clientX; touchStartClientY=e.touches[0].clientY; //console.log(touchStartClientX+','+touchStartClientY); }) document.addEventListener('touchend',function(e){ var touchendClientX,touchendClientY; touchendClientX= e.changedTouches[0].clientX; touchendClientY=e.changedTouches[0].clientY; //console.log(touchendClientX+','+touchendClientY); var sx=touchendClientX-touchStartClientX; var sy=touchendClientY-touchStartClientY; console.log(sx+','+sy); /* if(Math.abs(sx)>Math.abs(sy)){ if(sx>0) direction='right'; else direction='left'; }else{ if(sy>0) direction='down'; else direction='up'; }*/ direction=Math.abs(sx)>Math.abs(sy)?(sx>0?'right':'left'):(sy>0?'down':'up'); alert('direction='+direction); }) </script> </html>
效果预览:http://output.jsbin.com/wuqilofoyi 需要谷歌浏览器模拟一下手机看
#2015-08-28
The text was updated successfully, but these errors were encountered:
No branches or pull requests
效果预览:http://output.jsbin.com/wuqilofoyi 需要谷歌浏览器模拟一下手机看
#2015-08-28
The text was updated successfully, but these errors were encountered: