jquery FadeOut 一个类,运行多次,而不是同时运行,y?
我有一个页面,其中有几个 div,例如:
默认情况下,所有 div 都是显示:无,我让用户单击以显示特定的卡片。
每次用户单击加载卡片时,我都会运行以下 JQUERY:
$('.carditem').fadeOut( function() {alert(1)
// Animation complete show correct card
$('#' + toogleID).fadeIn();
});
令我惊讶的是,上面的警报发生了 5 次,而不是 1 次。这意味着淡出不是同时运行,而是循环遍历所有卡片项目。这会产生一个丑陋的闪烁动画。如何让所有匹配的类同时运行淡出?或者只是在具有正在显示的 div 的类上运行,该类应该只有 1 张卡?
谢谢!
I have a page with the several divs like:
By default all are display:none, and I let the user click to show a certain card.
Every time the user clicks to load a card I run the following JQUERY:
$('.carditem').fadeOut( function() {alert(1)
// Animation complete show correct card
$('#' + toogleID).fadeIn();
});
What's surprising me is that the alert above is happening 5 times, not 1 time. Meaning the fadeOut isn't running Simultaneously but looping over all the card items. This makes for a ugly animation that blinks. How can I get fadeout for all the matching classes to run at the same time? Or just run on the classes that have divs that are displaying, which should only be 1 card?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您取出停止动画的警报(导致偏移开始),它会按预期运行,至少在初始动画同时进行时是这样。:
每个元素确实独立地进行动画处理,如果您希望
.fadeIn()
在 最后其中一个,然后检查是否有任何仍在使用.is() 进行动画处理
和:animated
选择器,像这样::visible
添加到选择器以便只有可见的内容淡出,而不是显示/淡出所有内容。If you take out the alert which is stopping the animations (causing an offset start), it'll behave as expected, at least in terms of the initial animations being simultaneous.:
Each element does animate independently, if you want the
.fadeIn()
to happen after the last one of them, then check if any are still animating with.is()
and the:animated
selector, like this:The
:visible
addition to the selector is so that only visible ones are faded out, rather than showing/fading all of them.