I use twitter bootstrap 3 applying .fade
to show tabs with fade. That's fine except for the first tab's content is not shown for the first time:
http://jsfiddle.net/tVSv9/
<ul class="nav nav-tabs" id="myTab">
<li class="active"><a href="#home" data-toggle="tab">Home</a></li>
<li><a href="#profile" data-toggle="tab">Profile</a></li>
<li><a href="#messages" data-toggle="tab">Messages</a></li>
</ul>
<div id='content' class="tab-content">
<div class="tab-pane fade active" id="home">
<ul>
<li>home</li>
<li>home</li>
<li>home</li>
<li>home</li>
<li>home</li>
<li>home</li>
<li>home</li>
</ul>
</div>
<div class="tab-pane fade" id="profile">
<ul>
<li>profile</li>
<li>profile</li>
<li>profile</li>
<li>profile</li>
<li>profile</li>
<li>profile</li>
<li>profile</li>
</ul>
</div>
<div class="tab-pane fade" id="messages">
this is my message
</div>
<div class="tab-pane fade" id="settings"></div>
</div>
Where is the problem inside the code?
You need to add in
class to your active tab content
The reason behind is there is predefined style in bootstrap css .fade.in {opacity: 1;}
so if you are using .fade
in tab then you need to add .in
too
See this demo
HTML
<div class="tab-pane fade in active" id="home">
It is a bit peculiar, but I could think of a quick hack to get this running.
$('.nav li.active').removeClass('active').find('a').trigger('click');
Put the above script inside $(document).ready( function() { ... })
What it does is basically remove your pre-defined active class, and re-enable it by mocking the 'click' event.
Fiddle: http://jsfiddle.net/jofrysutanto/tVSv9/2/
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