jQuery,如何制作同步动画?

发布于 2024-09-11 02:27:05 字数 1192 浏览 4 评论 0原文

我有一个看起来像这样的页面布局

|    image    ||    image    ||    image    |

当您将鼠标悬停在其中一张图像上时,我想制作一个动画来获得类似的效果

|     image-hover     ||  image  ||  image  |

或者

|  image  ||     image-hover     ||   mage  |

|  image  ||  image  ||     image-hover     |

我使用了 .animate({width: width}, speed ) 并且工作正常。但有一件事困扰着我,动画不同步。结果就是右边框来回闪烁。在动画的中间,总宽度比应有的宽度窄了大约 3 像素。

我尝试过调整速度,但它对闪烁没有帮助,而且我没有看到整体动画有太大改进。

如果有什么区别,我将 divsbackground-imageoverflow: hide; 一起使用,包裹在 li 中> 标签。我正在使 lidiv 更宽(li 标记还包含一些文本。)

实际问题:
是否可以使动画同步,以便它们同时发生且流畅?

代码:

$(this).animate({width: 450}, 495)
    .parent("li").animate({width: 450}, 495)
    .next("li").animate({width: 225}, 500)
    .find(".class").animate({width: 225}, 500)
    .parent("li").next("li").animate({width: 225}, 500)
    .find(".class").animate({width: 225}, 500);

我尝试先进行遍历并将元素分配给两个变量,一个变大,一个变小,但这并没有真正改善情况。

I have a page layout that looks something like this

|    image    ||    image    ||    image    |

When you hover over one of the images, I want to make an animation to get something like this

|     image-hover     ||  image  ||  image  |

or

|  image  ||     image-hover     ||   mage  |

or

|  image  ||  image  ||     image-hover     |

I've used the .animate({width: width}, speed) and it works okay. But there is one thing that is bugging me, the animations is not synchronous. The result is that the right border is flickering back and forth. In the middle of the animation the total width is about 3 pixel slimmer than it should it.

I've tried tweaking the speeds, it doesn't help with the flickering, and I didn't see much improvement on the overall animation.

If it makes any difference, I'm using divs with background-image and overflow: hidden; wrapped in li tags. I'm making both the li and div wider (the li tag also hold some text.)

The actual question:
Is it possible to make the animations synchronous, so they happen at the same time nice and smooth?

The code:

$(this).animate({width: 450}, 495)
    .parent("li").animate({width: 450}, 495)
    .next("li").animate({width: 225}, 500)
    .find(".class").animate({width: 225}, 500)
    .parent("li").next("li").animate({width: 225}, 500)
    .find(".class").animate({width: 225}, 500);

I've tried doing the traversing first and assigning the elements to two variables, those to make bigger and those to make smaller, but that didn't really improve things.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-柠檬树下少年和吉他 2024-09-18 02:27:05

我认为您指的是 队列构建那里有问题。尝试在 animiatestop 方法> 方法例如:

$(...).stop().animate({width: width}, speed)

更多信息:

http://www .learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup

至于流畅的动画,你可以选择jQuery 缓动插件

I think you are referring to queue buildup problem there. Try using the stop method before the animiate method eg:

$(...).stop().animate({width: width}, speed)

More Info:

http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup

As for smooth animation, you can go for jQuery Easing Plugin.

鲜血染红嫁衣 2024-09-18 02:27:05

在动画中间
总宽度缩小约3像素
比它应该的。

尝试将缓动设置为线性。

In the middle of the animation the
total width is about 3 pixel slimmer
than it should it.

try to set easing to linear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文