我正在尝试隐藏一个通过 JavaScript hide()
$("#" + id).hide(2000);
我有一个 div,我试图这样隐藏,但似乎没有正确执行动画。
就这样消失了。
$("#" + id).hide(2000);
I have a div I'm trying to hide thusly, but doesn't seem to be doing the animation properly.
Just disappears.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的评论,我的猜测是您的代码在动画开始后立即删除它。动画是一个异步过程。您的代码将在动画开始后立即继续运行。如果您在调用
hide()
之后删除该对象,那么您将在动画完成之前删除它,并且它会“消失”而不是慢慢淡出。要解决这个问题,您需要在动画上添加一个完成事件,并且需要在完成后将其删除。
您将需要这样的东西:
只是为了向人们展示 .hide(2000) 函数工作得很好,这里有一个工作示例: http://jsfiddle.net/jfriend00/XDQwU/。
Based on your comments, my guess is that your code is deleting it right after the animation STARTED. The animation is an asychronous process. Your code will continue to run right after the animation is started. If you are then removing the object after the call to
hide()
, then you will be removing it before the animation has completed and it will "just disappear" rather than fade out slowly.To fix that, you will need a completion event on the animation and you will need to remove it upon completion.
You will need something like this:
Just to show people that the .hide(2000) function works just fine, here's a working example: http://jsfiddle.net/jfriend00/XDQwU/.