使用 jQuery 按顺序淡入列表项
我正在构建一个投资组合页面,其中包含不同项目的列表(在无序列表中)。在页面加载时,我想让每个“li”一个接一个地淡入。我已经实现了这样的目标:
var eT = 0;
$('.everything').hide().each(function() {
$(this).delay(eT).fadeIn('slow');
eT += 200;
});
我遇到的问题是,每个 li 将根据其代表的工作类型(网络、打印等)拥有一个(或多个)类。侧面有一个导航,可让您过滤要显示的作品类型。我遇到的是,如果我单击过滤器,而动画仍在项目中加载,事情就会变得非常混乱。
目前工作页面的模板如下: http://jjaakk.miller-interactive.com/templates/work.html
我一直在尝试很多事情,但成效有限。关于如何使这项工作以更稳定的方式进行有什么想法吗?
我尝试在单击时添加 .stop() ,但它没有按我的预期工作。
I'm building a portfolio page that has a list of different projects (in an unordered list). On page load I want to have each "li" to fade in, one after another. I have achieved this like so:
var eT = 0;
$('.everything').hide().each(function() {
$(this).delay(eT).fadeIn('slow');
eT += 200;
});
The problem I am having is that each li will have a class (or multiple) based on the type of work (web, print, etc) it represents. There is a navigation to the side that will allow you to filter the type of work to display. What I have encountered is that if I click the filters, while the animation is still loading in items, things get really messy.
Here is the template of the work page currently:
http://jjaakk.miller-interactive.com/templates/work.html
I have been trying many things, but with limited success. Any thoughts on how to make this work in a more stable manner?
I tried adding .stop() on click, but it has not worked as I intended.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这个问题与 jQuery Delay() 的限制有关。以下使用标准 javascript setTimeout 和 clearTimeout 根据 jQuery 延迟() API。
I think the problem was related to a limitation with jQuery delay(). The following uses standard javascript setTimeout and clearTimeout as suggested by the jQuery delay() api.
我知道您说过您尝试在单击时添加 .stop() 。下面的代码正是这样做的,但对我来说效果很好。如果这不是您想要的,请在评论中解释。
工作演示
I know that you said you tried adding the .stop() on click. The following code does exactly that, but works fine for me. If this is not what you are looking for, please explain in the comments.
Working Demo
按索引多重延迟
Multiple delay by index