下面是我的代码..
$(document).ready(function(){
$("#toggle-btn").click(function(){
$(".example").toggleClass("with-text");
});
});
如何添加时间toggleClass? 例如,我可以在任何地方添加“5000”,这样它就会在 5 秒内添加类?
谢谢。
最佳答案
使用setTimeout
var timer = null;
$("#toggle-btn").click(function(){
if(timer != null){
clearTimeout(timer )
}
timer = setTimeout(function () { $(".example").toggleClass("with-text"); }, 5000);
});
关于javascript - 使用toggleClass时如何添加时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092380/