小编fis*_*joe的帖子

有没有办法在jQuery或Javascript中确定touchmove事件的速度?

这是一个简单的问题.有没有办法在jQuery或Javascript中确定touchmove事件的速度?我使用css来抓取元素并让它可以抓取,这样可以正常但是如果我更快地移动手指,我不太可能移动到阈值距离但我确实打算翻页,所以有没有办法我可以确定javascript或jQuery中触摸移动事件的移动速度,我可以将阈值调整为较小的值以补偿速度?

    var startX, endX, difference, threshold; 
var startTime, endTime, timeDiff = 151;
$('#animate')
.bind("touchstart", function (e){ 
    e.preventDefault();
    var d = new Date();      
    startTime = d.getTime();
    startX = e.originalEvent.touches[0].pageX; //starting point
    })
.bind("touchmove", function (e){
    e.preventDefault();
    endX =e.originalEvent.changedTouches[0].pageX; //Get the information for finger 
    difference = startX - endX;  //calculate the distance moved.
    var moved = minusScreen - difference; //determine the affected css value.
    $(this).css("left",moved);  //this makes the element moves with my finger.
    })
.bind("touchend", function (e) { 
    var date = new …
Run Code Online (Sandbox Code Playgroud)

javascript performance jquery touch-event touchmove

0
推荐指数
1
解决办法
4500
查看次数

标签 统计

javascript ×1

jquery ×1

performance ×1

touch-event ×1

touchmove ×1