交错 jQuery 动画
我想在 jquery 1.3 中对一系列项目进行动画处理,每个下一个项目在第一个动画的中途开始。换句话说,我想要一个半队列的效果。我尝试使用下面的代码,但它不起作用。有人有什么想法吗?
$("h3").click(function(){
$(".projectItem").each(function (i) {
if (i > 0){
setTimeout ("", 500);
}
$(this).animate({"opacity": 0, "duration": 1000});
});
});
PS:我尝试使用各种“空闲”或“暂停”jquery 插件,但我怀疑使用的技术是 jquery 1.3 之前的技术?
PPS:预先感谢您的帮助:)
I want to animate a series of items in jquery 1.3, with each next item beginning halfway through the first animation. In otherwords, I want a half-queue effect. I attempted to use the below code, but it is not working. Does anyone have any ideas?
$("h3").click(function(){
$(".projectItem").each(function (i) {
if (i > 0){
setTimeout ("", 500);
}
$(this).animate({"opacity": 0, "duration": 1000});
});
});
PS: I attempted to use various "idle" or "pause" jquery plugins, but I suspect the techniques used were pre jquery 1.3?
PPS: Thanks in advance for your help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试这样的操作:
这里的总体思路是使用
.projectItem
列表 - 将动画从开始延迟到每个项目 500 毫秒。第一项 (i=0
) 将有 0 毫秒的延迟,并在下一个事件循环期间(几乎)立即执行。每个其他项目都会在其之前延迟 500 毫秒,并且由于您的动画持续 1000 毫秒,因此它将在最后一个项目动画的大约一半处开始。You could try something like this:
The general idea here is using your list of
.projectItem
- you delay the animation from beginning until 500ms per item. The first item (i=0
) will have a 0ms delay and execute (almost) immediately during the next event loop. Each other item will be delayed by 500ms per item before it, and since your animation lasts 1000ms, it will start approximately halfway through the last items animation.我认为将动画分成两部分(从不透明度 1 到 0.5,以及从 0.5 到 0)并使用常规队列(如果可能的话)会更简单。
如果我们从不透明度 1 开始,则此代码为:
I think it's simpler to break the animation to 2 parts (from opacity 1 to 0.5, and from 0.5 to 0) and use regular queue (if the breaking is possible).
This code is if we start at opacity 1: