html5,触摸方向判定

发布:2018-08-07 07:50   点击51次   评论:0

$("body").on("touchstart", function(e) {
$('.pswp__ui--idle .pswp__button--arrow--left').css('opacity',1);
    e.preventDefault();
    startX = e.originalEvent.changedTouches[0].pageX,
    startY = e.originalEvent.changedTouches[0].pageY;

});

$("body").on("touchmove", function(e) {
    e.preventDefault();
    moveEndX = e.originalEvent.changedTouches[0].pageX,
    moveEndY = e.originalEvent.changedTouches[0].pageY,
    X = moveEndX - startX,
    Y = moveEndY - startY;
if( Math.abs(X) > Math.abs(Y) && X > 0 ) {

//$(".pswp__button--arrow--right").trigger("click");
//alert(1);
}else if  ( Math.abs(X) > Math.abs(Y) && X < 0 ) {
//$(".pswp__button--arrow--left").trigger("click");
}else if  ( Math.abs(Y) > Math.abs(X) && Y > 0) {
//alert("top 2 bottom");
}else if  ( Math.abs(Y) > Math.abs(X) && Y < 0 ) {
//alert("bottom 2 top");
}else{
//alert("just touch");
}
});

关于 GitHub 导航 部门 反馈

提示:`/home.php`入口数据仅为演示功能,不构成任何交易凭证,也不承担相关风险和责任!

Copyright © 2011-2018 xxxxx.com All rights reserved.

Run:3.257/35.481(ms); 7(sql)/2.877(MB); comm:news/detail; Upd:2024-03-29 10:28:41