javascript - delay() 函数不适用于 jquery 中的 addClass() 函数

标签 javascript jquery css

当我在 addClass() 函数之前使用 delay() 函数时,类 circle1 不会延迟一段时间。

我的代码如下……

CSS:

.but{display:block; width:40px; height:40px; background-color:#F00; position:absolute;}

.circle1{display:block; width:145px; height:145px; position:absolute; left:10px; bottom:0px; border-radius:50%; border:5px solid rgba(100%,0%,20%,0.7); background-image:url(New%20folder/1st.jpg); background-position:center; background-repeat:no-repeat; background-size:cover; transform:scale(0);}
.zoom{transform:scale(1); transition:All 0.4s ease;}

JQuery:

$(document).ready(function() {
    $(".but").click(function() {
         $('.but').fadeOut(300);
         $('.circle1').delay(1000);
         $('.circle1').addClass("zoom");
    });
});

最佳答案

使用setTimeout ,因为 .delay() 被设计为与队列一起工作,因为 addClass() 不要使用队列。

$(".but").click(function() {
     $('.but').fadeOut(300);
     setTimeout(function(){
         $('.circle1').addClass("zoom");
     }, 1000);        
});

或者,您可以使用 .queue

$(".but").click(function() {
     $('.but').fadeOut(300);    

     $('.circle1').delay(100)
               .queue(function() {
                   $(this).addClass("zoom");
                   $(this).dequeue();
               });

});

关于javascript - delay() 函数不适用于 jquery 中的 addClass() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28668746/

相关文章:

javascript - 使用 JavaScript 更改 CSS 值

javascript - 预填充页面上的表单数据从 session 存储重新加载

jquery datepicker css 样式禁用日期

html - 如何向 WordPress 菜单栏添加 2 条条纹?

javascript - 使用node js搜索字符串mongodb中的任何单词

javascript - 时刻格式详细日期作为日期对象

javascript - 如何使用 jquery 捕获输入中的更改事件?

CSS 无序列表对齐

javascript - 使用本地主机测试 Facebook 共享对话框 - "Unable to resolve object at URL http://localhost"

javascript - 将变量值插入ajax post数据