如何同时淡入和动画?
我使用 jQuery 创建一个基本的“工具提示”动画,以便工具提示将出现在一个小动画中,在该动画中它会淡入视图并垂直移动。
到目前为止,我有这样的:
$('.tooltip').fadeIn('slow');
$('.tooltip').animate({ top: "-10px" }, 'slow');
这样做或这样:
$('.tooltip').fadeIn('slow').animate({ top: "-10px" }, 'slow');
动画将一次运行一个,首先淡入,然后是垂直动画。有没有办法让它同时做这两件事?
Using jQuery I'm creating a basic 'tooltip' animation so that the tooltip will appear in a little animation in which it fades into view as well as move vertically.
So far I have this:
$('.tooltip').fadeIn('slow');
$('.tooltip').animate({ top: "-10px" }, 'slow');
Doing it that way or this way:
$('.tooltip').fadeIn('slow').animate({ top: "-10px" }, 'slow');
The animations will run one at a time, the fade in first and then the vertical animation. Is there a way to have it do both at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于几年后仍在寻找的人来说,情况发生了一些变化。您现在也可以将
queue
用于.fadeIn()
,这样它的工作方式如下:这具有在
display: none 元素,这样您就不需要额外的两行代码。
For people still looking a couple of years later, things have changed a bit. You can now use the
queue
for.fadeIn()
as well so that it will work like this:This has the benefit of working on
display: none
elements so you don't need the extra two lines of code.如果您想单独调用它们(例如,从不同的代码),则执行同步动画的另一种方法是使用队列。再次,正如 Tinister 的答案一样,您必须为此使用 animate 而不是 fadeIn:
Another way to do simultaneous animations if you want to call them separately (eg. from different code) is to use
queue
. Again, as with Tinister's answer you would have to use animate for this and not fadeIn:但是,这似乎不适用于
display: none
元素(如fadeIn
那样)。所以,你可能需要提前把这个:However, this doesn't appear to work on
display: none
elements (asfadeIn
does). So, you might need to put this beforehand: