简体   繁体   English

jQuery的remove()绕过FX队列? 如何仅在链的末端使用它?

[英]jQuery's remove() bypass the FX queue? How do I use it only at the end of my chain?

I have a button with this behavior: it disappears once clicked; 我有一个具有此行为的按钮:单击该按钮便消失; then a small message fade in for a couple seconds, fades out and the button reappears again. 然后一则小消息消失了几秒钟,然后消失了,按钮再次出现。

To show the small message I append a element after my hidden button but need to remove it from the DOM once it has faded out. 为了显示小消息,我在隐藏按钮之后添加了一个元素,但是一旦它消失了,就需要将其从DOM中删除。 However, as soon as I use remove() in the chain the element is deleted and never fadeIn/fadeOut! 但是,一旦我在链中使用remove(),该元素就会被删除,并且从不褪色!

// the button is generated dynamically
$('#myButton').live('click', function() {
    $(this)
        .fadeOut() // once clicked, the button disappears

        .after('<small style="display:none;">Dans panier</small>') // append the message after the button

        .next('small').fadeIn() // fade the new small message for a smooth effect

        .delay(1000) // leave it visible for a second...

        .fadeOut() // then fade it out

        .remove() // <-------- normally I would have remove it here from the DOM because it should be hidden, but the remove() method seems to be bypassing the other ones and the small message never shows up!

        .end() // stop using this object and return to the button

        .delay(1000) // use the same delay as the small message so they are timed

        .fadeIn(); // show it back at the end
});

If you want to remove it after the fadeOut, you can use the callback method: 如果要在fadeOut之后将其删除,则可以使用回调方法:

[...]
.fadeOut(function(){ $(this).remove(); })

But once you remove it, you must insert back in in the DOM for it to reappear with the fadeIn . 但是,一旦将其删除,则必须重新插入DOM中,以便它与fadeIn一起重新出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM