jQuery 回调不等待淡出
在我看来,以下代码应该产生这些结果:
mademoiselle
demoiselle
mesdemoiselles
相反,随着“ma”淡出,“mes”在制作序列时淡出:
mademoiselle
madesdemoiselles
mesdemoiselles
代码:
<span class="remove">ma</span><span class="add">mes</span>demoiselle<span class="add">s</span>
$(document).ready(function() {
$(".remove").fadeOut(4000,function(){
$(".add").fadeIn(5000);
});
});
编辑:我发现一个空的范围,如果我删除它会使错误消失:
<span class="remove">ma</span><span class="add">mes</span>demoiselle<span class="remove"></span><span class="add">s</span>
问题是:生成此代码的 php 代码使用 span 作为占位符。如果有必要,我会 str_replace 它们,但我很好奇为什么会发生这种情况。
It seems to me the following code should produce these results:
mademoiselle
demoiselle
mesdemoiselles
Instead, as "ma" fades out, "mes" fades in making the sequence:
mademoiselle
madesdemoiselles
mesdemoiselles
The code:
<span class="remove">ma</span><span class="add">mes</span>demoiselle<span class="add">s</span>
$(document).ready(function() {
$(".remove").fadeOut(4000,function(){
$(".add").fadeIn(5000);
});
});
Edit: I found an empty span that if I remove makes the bug go away:
<span class="remove">ma</span><span class="add">mes</span>demoiselle<span class="remove"></span><span class="add">s</span>
The problem is: The php code generating this is using the spans as placeholders. I'll str_replace them if I have to, but I'm curious why this is happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我设法重现了您的问题,请参阅 http://jsbin.com/ocaha 中的示例。
发生的情况是 jQuery 可以看到您的空
不需要淡出。因此,它认为动画已完成并执行 0 毫秒,而不是预期的 4000 毫秒。因此它立即开始在
.adds
的全部中淡出。为了防止这种行为,我会过滤从选择中删除所有空元素。像这样:
请参阅 http://jsbin.com/ovivi 上的工作示例。
Ok, so I managed to reproduce your problem see the example at http://jsbin.com/ocaha.
What's happening is that jQuery can see that your empty
<span>
does not need to be faded out. Therefor it considers the animation done and executes for 0ms instead of the expected 4000ms. So it immediately starts fading in all of the.adds
.To prevent this behaviour, I would filter away all empty elements from the selection. Like this:
See working example at http://jsbin.com/ovivi.
如果不起作用,请将“:空”更改为“:隐藏”:
Change ":empty" to ":hidden" if not working: