jquery:我怎样才能阻止appendTo立即发生?
我一直在谷歌上搜索并尽我的一生尝试延迟appendTo立即发生,这样我就可以先做一个漂亮的淡出。在这里, myObject 是一个链接:
<a href="#">My Link</a>
我想将其移动到无序列表中:
<div id="newDiv">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
通过执行以下操作:
myObject.fadeOut(300).appendTo('#newDiv ul').fadeIn(300);
myObject.wrap('<li></li>');
我知道appendTo 不是动画对象,所以它会立即发生。所以我尝试将追加作为 fadeOut 的回调:
myObject.fadeOut(300, myObject.appendTo('#newDiv')).fadeIn(300);
myObject.wrap('<li></li>');
只是现在它不仅立即发生,换行也不再起作用。我还尝试使用 setTimeout 来延迟附加,但无济于事。
I have been googling and trying for the life of me to delay appendTo from happening instantly, so that I can do a nice fadeout first. Here, myObject is a link:
<a href="#">My Link</a>
And I would like to move it into an unordered list:
<div id="newDiv">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
By doing something like this:
myObject.fadeOut(300).appendTo('#newDiv ul').fadeIn(300);
myObject.wrap('<li></li>');
I know that appendTo isn't an animation object though, so it just happens instantly. So I tried putting the append as a callback to fadeOut:
myObject.fadeOut(300, myObject.appendTo('#newDiv')).fadeIn(300);
myObject.wrap('<li></li>');
Only now it not only happens instantly, the wrap no longer works. I've also tried using a setTimeout to delay the appending to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
通过在淡入淡出的回调中执行“appendTo”,您可以等到淡入淡出完成。所有(据我所知)jQuery 动画效果都采用这样的回调。
Try this:
By doing the "appendTo" in the callback from the fade, you can wait until the fade is done. All (as far as I know) the jQuery animation effects take callbacks like that.