I can't figure it out why my div won't fadeIn after FadeOut finishes.
Heres my Html:
<div class="header-container">
<header class="wrapper clearfix">
<ul class="nav nav-tabs">
<li class="active">
<a href="#tab1">Section 1</a>
</li>
<li>
<a href="#tab2">Section 2</a>
</li>
</ul>
</header>
</div>
<div class="main-container">
<div class="main wrapper clearfix">
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<p>I'm in Section 1.</p>
</div>
<div class="tab-pane" id="tab2">
<p>Howdy, I'm in Section 2.</p>
</div>
</div>
</div> <!-- #main -->
</div> <!-- #main-container -->
My JS
jQuery(document).ready(function(){
$('.nav-tabs a').click(function (e) {
e.preventDefault();
var href = $(this).attr('href'); // Select first tab
$('.tab-pane').fadeOut(1000,function(){
$(href).fadeIn(1000);
});
});
});
My Css
.tab-pane {
display: none;
}
I made a jsfiddle:
http://jsfiddle.net/JohnnyDevv/hKq2K/1/
I made it simple as possible... Thanks in advance
The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.
The jQuery fadeTo() method allows fading to a given opacity (value between 0 and 1).
The fadeIn() method gradually changes the opacity, for selected elements, from hidden to visible (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeOut() method.
fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none , so the element no longer affects the layout of the page. Durations are given in milliseconds; higher values indicate slower animations, not faster ones.
This will output the desired result you are expecting:
$('.tab-pane').fadeOut(1000).promise().done(function(){
$(href).fadeIn(1000);
});
.promise()
ensures to complete the fadeOut()
first then when it completes .done()
executes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With