等待 javascript 显示一个元素,然后隐藏它
你好,我有一个 JQuery js,它在 AJAX 调用后执行类似的操作:
$element.next().after('<td><b>OPTION SAVED</b></td>');
$element.next().next().hide();
$element.next().next().show('slide', {direction : 'left'}, 1000);
现在我想做的是调用这个 =>
$element.next().next().next().hide("slow");
所以基本上我想动态创建一个元素,从左侧滑动它,在它出现后,我希望它再次慢慢隐藏它。我该怎么做?我的问题是,即使元素尚未完成滑动(或者可能是其创建?),也会执行 js 代码,所以当我调用 hide("slow") 时,它告诉我我在未定义上调用它,但没有任何反应...
谢谢
Hi I have a JQuery js that does something like this after AJAX call:
$element.next().after('<td><b>OPTION SAVED</b></td>');
$element.next().next().hide();
$element.next().next().show('slide', {direction : 'left'}, 1000);
Now what I want to do is call this =>
$element.next().next().next().hide("slow");
So basically I want to create an element dynamically, slide it from the left and after it has appeared, I want it to hide it slowly again. How do I do this? My problem is that js code is executed even while the element has not yet completed the sliding (or its creation maybe?) so When I call hide("slow") it tells me I called it on undefined and nothing happens...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该可以,调用的链接意味着 after 将返回您刚刚添加的元素,然后显示它并添加回调函数以再次隐藏它。
Should work, the chaining of the calls means the after will return the element you just added then you show it and add a callback function to hide it again.
如果我理解你对问题的描述。您的问题是您的
next
太多。请注意,这里有 2 个
next
。然后是 3
next
。 不是相同的元素。如果您想隐藏相同的元素,请从hide
中删除next
。或者更好的是,直接链接它:
If I'm understanding your description of the problem. Your issue is that you have one too many
next
s.Note that there are 2
next
s here.Then here are 3
next
s. NOT the same element. If you want to hide the same element then drop anext
off of thehide
.Or even better, just chain it:
您应该使用回调函数:
动画完成后将执行回调函数。
再见 !
You should use a callback function :
Callback function will be executed once animation is complete.
Bye !