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

匆匆过客 提交于 2019-12-17 15:36:47

问题


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


回答1:


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);
});



回答2:


Not quite like that, but like this for example:

$("#info-text").delay(500).queue(function(next) {
  $(this).addClass("info-text-active");
  next();
});


来源:https://stackoverflow.com/questions/15448344/can-i-put-delay500-before-an-addclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!