Can I put delay(500) before an addClass()?

2019-01-13 16:04发布

$(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!

2条回答
Luminary・发光体
2楼-- · 2019-01-13 16:38

Not quite like that, but like this for example:

$("#info-text").delay(500).queue(function(next) {
  $(this).addClass("info-text-active");
  next();
});
查看更多
聊天终结者
3楼-- · 2019-01-13 16:59

delay only works with animating methods, you can use setTimeout function:

$("#info-text-container").click(function(){
    setTimeout(function(){
       $("#info-text").addClass("info-text-active");
   }, 500);
});
查看更多
登录 后发表回答