jQuery 动画队列
我陷入了困境,所以希望 jQuery 专家能够提供帮助。
我的页面上总共有 10 个元素(实际上是小图像)。我需要像这样对它们进行动画处理:
- 前 2 个显示
- ,然后下 2 个显示
- ,然后下 3 个显示
- ,然后下一个 1 显示
- ,最后 2 个显示
所以,我为每个显示添加了属性 (sequence_num = "1 “(或 2 或 3 等),因此我可以通过 $() 轻松选择使用 animate() 函数对哪些动画进行动画处理。)
我的目标是编写一个执行动画的函数(我可以做到这一点 - 我想我已经掌握了 animate() 函数)。
我遇到的问题是如何延迟动画,以便在下一组开始之前对正确的对象组进行动画处理。我已经尝试过 animate() 函数的队列参数,但这似乎不适用于我想要做的事情。
有人有这方面的经验吗?
I am at a dead end, so hoping you jQuery gurus can help.
I have a total of 10 elements (actually small images) on a page. I need to animate them like this:
- first 2 show up
- then the next 2 show up
- then the next 3 show up
- then the next 1 shows up
- then the last 2 show up
So, I have added attributes to each one (sequence_num = "1" (or 2 or 3 etc) so I can easily choose via the $() which ones to animate using the animate() function.)
My goal is to write a function that does the animation (I can do that - i think i have grasped the animate() function).
What I am getting stuck on is how to delay the animation so the proper groups of objects are animated in before the next group starts. I have tried the queue parameter of the animate() function, but that doesn't seem to work for what I am trying to do.
Does anyone have any experience with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
避免使用巨大的回调“圣诞树”,或者尝试使用 setTimeout 来恰到好处地计时。
这会触发一个又一个动画,并且可以轻松扩展,无需毫秒计算或消失在编辑器屏幕右侧之外的代码。
Avoid a huge "christmas tree" of callbacks, or trying to time it just right with setTimeout.
This triggers one animation after another, and is easily extendable with no millisecond-calculations or code that disappears outside the right hand side of your editor screen.
在这种情况下,使用可以提供给 animate() 的回调函数而不是内置队列可能会更容易。动画结束时会调用回调,因此当调用它时,会找到下一个元素并对它们进行动画处理,依此类推,直到元素用完。
In this case it might be easier to use the callback function you can supply to animate() instead of the build-in queuing. The callback is called when the animation ends, so when it's called, find the next elements and animate them and so on until you run out of elements.