Jquery淡入/淡出动画问题
我正在使用 Jquery FadeIn/FaeOut 在我的页面上显示和隐藏内容。像这样:
$('.subnav_company').click(function(){
$('.aboutcontent').fadeOut('slow');
$('.company').fadeIn('slow');
});
我的问题是,因为当显示“.company”时,div“.company”位于“.aboutcontent”下方,因此它显示在“.aboutcontent”下方,直到 div 完全隐藏,从而产生不平滑的过渡效果。
如何使 div 的显示和隐藏之间的过渡平滑?不神经质。这是 HTML:
<div class="aboutcontent developers">
<h1>Developers</h1>
<h4>The developers are the best</h4>
<p> we have some great developers</p>
</div>
<!--End aboutcontent developers-->
<div class="aboutcontent company">
<h1>Company</h1>
<h4>offers a complete management tool . It's an easy to use and efficient way to manage and plan stuff. It allows people to communicate and get along.</h4>
</div>
<!--End aboutcontent company-->
I am using Jquery FadeIn/FaeOut to show and hide content on my page. Like so:
$('.subnav_company').click(function(){
$('.aboutcontent').fadeOut('slow');
$('.company').fadeIn('slow');
});
My problem is that because the div '.company' is positioned below '.aboutcontent' when '.company' is shown it appears below '.aboutcontent' until the div has hidden fully, creating a unsmooth transition effect.
How can I make the transition between showing and hiding the divs smooth? Not jumpy. Here is the HTML:
<div class="aboutcontent developers">
<h1>Developers</h1>
<h4>The developers are the best</h4>
<p> we have some great developers</p>
</div>
<!--End aboutcontent developers-->
<div class="aboutcontent company">
<h1>Company</h1>
<h4>offers a complete management tool . It's an easy to use and efficient way to manage and plan stuff. It allows people to communicate and get along.</h4>
</div>
<!--End aboutcontent company-->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
.fadeOut()
的回调,如下所示:您可以在这里尝试一下,这不会触发
.company
上的.fadeIn()
直到上淡入淡出.aboutcontent
已完成。由于您要淡出许多面板,其中一些面板已经隐藏,因此使用
:visible
选择器 因此回调仅在淡入淡出后触发,而不是在淡入淡出立即完成的选择器后立即触发......因为它已经隐藏了。You can use the callback for
.fadeOut()
, like this:You can give it a try here, this won't trigger the
.fadeIn()
on.company
until the fade on.aboutcontent
is complete.Since you're fading out many panels, some of which are already hidden, it's important to use the
:visible
selector so the callback only triggers after the fading one, not instantly from the one who's fade completes instantly...because it's already hidden.