Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twitter bootstrap 3 tab view fade does not work properly

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?

like image 270
werva Avatar asked Sep 12 '13 06:09

werva


2 Answers

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">
like image 138
Vikas Ghodke Avatar answered Nov 09 '22 18:11

Vikas Ghodke


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/

like image 45
JofryHS Avatar answered Nov 09 '22 16:11

JofryHS