jQuery fadeOut/fadeIn 未按预期工作?
我试图根据用户的选择一次显示一个fieldset
。理论上,所有字段集应先隐藏,然后显示选定的字段集。我正在使用 jQuery 的 fadeOut
和 'fadeIn` 函数。
您可以在此处看到这个小提琴。
但效果并不好。怎么了?当您更改所有权类型时,首先显示两个字段集,然后它们变暗并淡出,然后出现预期的字段集。然而,期望的行为是,在更改所有权类型时,当前可见的字段集会淡出,然后预期的字段集会淡入。
I'm trying to show one fieldset
at a time, based on the user's selection. The theory is that, all fieldsets should hide first, then the selected fieldset should be shown. I'm using jQuery's fadeOut
and 'fadeIn` functions.
You can see a fiddle of this here.
But it doesn't work just fine. What's wrong? When you change the ownership type, first two fieldsets are shown, then they dim and fade out, and then the intended fieldset appears. However, the desired behavior is that, on change of the ownership type, the currently visible fieldset simply fade out, and then the intended fieldset fade in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用“承诺”http://api.jquery.com/jQuery.when/ 确保淡入发生在 fieldset 淡出之后。
http://jsfiddle.net/DtaHQ/26/
You can also use a 'promise' http://api.jquery.com/jQuery.when/ to be sure that fadein happens after when fieldset has faded out.
http://jsfiddle.net/DtaHQ/26/
问题是您已经隐藏了
fieldset
并且对于这些元素,fadeOut
的动画会立即触发,因为它已经隐藏了。尝试更改为:
代码:http://jsfiddle.net/DtaHQ/20/
The problem is that you already have hidden
fieldset
and for these elements animation of thefadeOut
fires immediately, because of it's already hidden.Try to change to this:
Code: http://jsfiddle.net/DtaHQ/20/
将代码更改为
您只想淡出当前可见的字段集。
http://jsfiddle.net/DtaHQ/24/
Change your code to
You only want to fade out the fieldset that is currently visible.
http://jsfiddle.net/DtaHQ/24/