如何让这个js函数在触摸屏幕一秒后执行 和 如果我继续在同一位置触摸屏幕一秒钟,如何使其成为同一触摸位置的一秒钟?
function onCanvasTouchStart(event)
{
if(event.touches.length == 1)
{
// draw
event.preventDefault();
brush.strokeStart((event.touches[0].pageX) - canvas.offsetLeft, (event.touches[0].pageY) - canvas.offsetTop);
window.addEventListener('touchmove', onCanvasTouchMove, false);
window.addEventListener('touchend', onCanvasTouchEnd, false);
}
}
最佳答案
使用setTimeOut .
function onCanvasTouchStart( event ){
if(event.touches.length == 1){
setTimeout(function(){
// draw
event.preventDefault();
brush.strokeStart( (event.touches[0].pageX) - canvas.offsetLeft, (event.touches[0].pageY) - canvas.offsetTop );
window.addEventListener('touchmove', onCanvasTouchMove, false);
window.addEventListener('touchend', onCanvasTouchEnd, false);
}, 1000);
}
}
关于javascript - 如何在函数执行之前等待一秒钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36314591/