在您的touchend事件侦听器上,var distX与触摸(swipe)所走的距离有关。您可以添加其他
if条件
从以下位置更新代码:
touchsurface.addEventListener('touchend', function(e){
var touchobj = e.changedTouches[0]
distX = touchobj.pageX - startX
distY = touchobj.pageY - startY
elapsedTime = new Date().getTime() - startTime
if (elapsedTime <= allowedTime){
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint){
swipedir = (distX < 0)? 'left' : 'right'
}
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint){
swipedir = (distY < 0)? 'up' : 'down'
}
}
handleswipe(swipedir)
e.preventDefault()
}, false)
进入这个
touchsurface.addEventListener('touchend', function(e){
var touchobj = e.changedTouches[0]
distX = touchobj.pageX - startX
distY = touchobj.pageY - startY
elapsedTime = new Date().getTime() - startTime
if(distX == 0){
alert('test click'); //this is where click event is detected
} else if (elapsedTime <= allowedTime){
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint){
swipedir = (distX < 0)? 'left' : 'right'
}
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint){
swipedir = (distY < 0)? 'up' : '
}
}
handleswipe(swipedir)
e.preventDefault()
}, false)
http://jsfiddle.net/8rscLo1z/14/show