[英]Stop click event in 500ms, how i can do this?
Hello i created memory game with js and jQuery and i have one small problem , because right now someone can display more then 2 hidden elements before they hide again. 您好我用js和jQuery创建了内存游戏,但我有一个小问题,因为现在有人可以显示2个以上的隐藏元素,然后才能再次隐藏。
if(arr1[0] === arr1[1]){
score += 10;
setTimeout(function () {
$board.find('[data-id="'+arr1[0]+'"]').remove()
arr1 = [];
scoreHTML.text(score)
},500)
} else if (arr1.length === 2 && arr1[0] !== arr1[1]) {
e.preventDefault();
setTimeout(function () {
$('.box').data('data-id', arr1[0]).fadeIn();
$('.box').data('data-id', arr1[1]).fadeIn();
arr1 = [];
},500)
}
Anyone have idea how i can block click event on this Timeout ? 任何人都知道如何在此超时时间内阻止点击事件?
Shouldn't you clear the timeout when you don't want it to be executed ? 当您不希望执行超时时,您是否应该清除超时?
clearTimeout(this.timeoutId);
if (someCondition) {
this.timeoutId = setTimeout(function () {
// Do something
},500);
} else {
this.timeoutId = setTimeout(function () {
// Do something else
},500);
}
(I used this.timeoutId assuming the code is embedded in a class but otherwize you could still use a variable) (我使用this.timeoutId假设代码已嵌入到类中,但否则您仍然可以使用变量)
I'm not sure i get your question right, but hope this helps. 我不确定我是否正确回答了您的问题,但希望能对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.