jQuery序列淡出然后删除 [英] jquery sequence fadeOut and then remove

查看:78
本文介绍了jQuery序列淡出然后删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试$('somediv').fadeOut.remove(); 但它只能将其删除,砰……它不必等待漂亮的渐变,然后将其删除

I try $('somediv').fadeOut.remove(); but it only remove it, bang... it dont wait for the nice fadeOut, and THEN remove

为什么..如何尊重淡入淡出,然后删除..

why.. how to respect fadeout, and then remove..

推荐答案

使用回调:

$('somediv').fadeOut( function() { $(this).remove(); });

您要传递给 fadeOut() (docs) 在动画完成之前不会执行.

The code in the callback function you're passing to fadeOut()(docs) will not execute until the animation is complete.

示例: http://jsfiddle.net/p2LWE/

另一种选择是 queue() (docs) remove() (docs) ,但我认为回调效果更好.

An alternative would be to queue()(docs) the remove()(docs) , but I think the callback is better.

$('somediv').fadeOut()
            .queue(function(nxt) { 
                $(this).remove();
                nxt();
            });

这篇关于jQuery序列淡出然后删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆