I am trying to use transitions in tabbed layout.
I am working on Laravel Framework. My js code doesn't work...
Desired outcome: the tab content appear and disapper with transitions implemented.
Now: the tabs switch properly, but instantly - with no transitions.
$('#tabnavigation .item').click(function() {
$('.ui .tab .segment').transition('slide down');
});
my view looks like this:
<a class="item red active" data-tab="first">One</a>
<a class="item blue" data-tab="second">Two</a>
<a class="item blue" data-tab="third">Three</a>
<a class="item blue" data-tab="fourth">Four</a>
<a class="item blue" data-tab="fifth">Five</a>
</div>
<div class="ui tab segment active" data-tab="first">
@include('widgets._15_elections_introduction')
</div>
<div class="ui tab segment" data-tab="second">
@include('widgets._15_elections_bycandidate')
</div> {{-- second --}}
<div class="ui tab segment" data-tab="third">
@include('widgets._15_elections_byelectoralcommitee')
</div>
<div class="ui tab segment" data-tab="fourth">
@include('widgets._15_elections_add_refine')
</div>
<div class="ui tab segment" data-tab="fifth">
@include('widgets._15_elections_help')
</div>
Anyone to help me?
The reason why nothing happens is because your selector is wrong -
.ui .tab .segment
means you are looking for an element that has the class segment inside an element that has the class tab inside an element that has the class ui. Instead, what you need to look for is an element that has all those classes, meaning you need to remove the spaces. If you'd like to learn more about selectors, this might be a good place to start.In short, replacing
$('.ui .tab .segment').transition('slide down');
with$('.ui.tab.segment').transition('slide down');
will make it work...well, sort of. It still won't do what you want since, at the time your click event happens, the tab is already displayed and the transition method will simply hide it.In order to do what you want, you need to:
Here's the code that does just that:
Note: I used Semantic UI's onVisible event instead of the click event - this is generally a good idea and it makes sure the tab content became visible, so that we can hide it and animate it.