0

在所有动画完成后,我需要完全从元素中删除不透明样式。
http://jsfiddle.net/SthJy/1/

我尝试设置但没有效果css('opacity', '')removeAttr('style')inilne 风格仍然存在。有人可以帮我解决这个问题吗?

4

2 回答 2

2

delay不适用于css()removeAttr()因为它们不可排队。delay()在文档中阅读更多内容

您需要使用css()removeAttr()在最终动画的完整调用中

 $("#helpCloud").animate({opacity: 1}, 200)
                .delay(2200)
                 .animate({  opacity: 0 }, 200, function(){
                      setTimeout(function(){
                          $(this).removeAttr('style');
                      }, 300);
                 });

由于元素的默认不透明度在 css 中为零,因此不确定您希望看到什么

API 参考:http: //api.jquery.com/delay

于 2013-01-12T19:27:14.830 回答
2

通过使用 .queue() 您可以保持与动画同步。

$("#helpCloud").animate({ opacity: 1 }, 200)
            .delay(2200)
            .animate({ opacity: 0 }, 200)
            .delay(300)
            .queue(function(next) {
              $(this).css('opacity', '');
              alert('happend only after .delay is over');
              next()
             })

现场演示:http: //jsfiddle.net/SthJy/3/

另一种获得相同结果的方法是在 .dalay(300, function() {}); 上使用回调

$("#helpCloud").animate({ opacity: 1 }, 200)
                .delay(2200)
                .animate({ opacity: 0 }, 200)
                .delay(300, function() {
                  $(this).css('opacity', '');
                  alert('happend only after .delay is over');
                });

现场演示:http: //jsfiddle.net/SthJy/4/

于 2013-01-12T19:31:59.593 回答