我有一个if语句,条件是如果numberOfFingers == 5那么计数器将增加1,我希望计数器仅在numberOfFingers的持续时间为5秒时增加1。 (这是跳跃运动)这可能吗?
if (numberOfFingers == 5) {
var start = parseInt(document.getElementById('count').innerHTML);
var end = start+1;
document.getElementById('count').innerHTML = end;
}
答案 0 :(得分:0)
看看“setTimeout”并尝试这样的事情:
if(numberOfFingers == 5) {
setTimeout(function(){
if(numberOfFingers == 5){ //5 fingers still after 5s
var start = parseInt(document.getElementById('count').innerHTML);
var end = start+1;
document.getElementById('count').innerHTML = end;
}
}, 5*1000); //your 5s
}