jQuery 我可以在 addClass() 之前放置 delay(500) 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15448344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:03:54 来源:igfitidea点击:
Can I put delay(500) before an addClass()?
提问by user2097217
$(document).ready(function(){
$("#info-text-container").click(function(){
$("#info-text").delay(500).addClass("info-text-active");
});
});
This does not put an delay on it when it gets clicked. Which I want to accomplish. Why and is this hackable, possible to overcome? Thanks!
当它被点击时,这不会延迟它。我想要完成的。为什么以及这是可破解的,可以克服吗?谢谢!
回答by undefined
delay
only works with animating methods, you can use setTimeout
function:
delay
仅适用于动画方法,您可以使用setTimeout
函数:
$("#info-text-container").click(function(){
setTimeout(function(){
$("#info-text").addClass("info-text-active");
}, 500);
});
回答by elclanrs
Not quite like that, but like this for example:
不太像那样,但像这样例如:
$("#info-text").delay(500).queue(function(next) {
$(this).addClass("info-text-active");
next();
});