I'm currently trying to build a tabbed div container:
At the moment it looks like this. I can also switch the tab. Each tab has an is-active
class.
To show the user which tab is active, I've added a border under each tab. When I change tab now, the border get's hardly changed. So removed from the left one and added to the right one.
Because this looks not so pretty I thought Is it possible to add the border with an animation sliding from the left to the right or back to the left when pressing the tab title?
So it should looks like fading from tab to the other one. Any idea how to deal with this?
This is my simplified code:
jQuery(ul.tabs li).click(function(){
var e = jQuery(this).attr(aria-controls);
jQuery(this).hasClass(active)||(jQuery(li).removeClass(active),jQuery(this).addClass(active),jQuery(#+e).show())})
ul.tabs {
margin: 0!important;
padding: 0!important;
background: #f4f4f4;
display: flex;
}
ul.tabs li {
flex-grow: 50;
list-style: none;
text-align: center;
background: #fff;
line-height: 45px;
cursor: pointer;
}
ul.tabs li a {
color: black;
text-decoration: none;
}
ul.tabs li.active {
cursor: default;
border-bottom: 2px solid red;
}
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
<ul class=tabs wc-tabs role=tablist>
<li class=description_tab active id=tab-title-description role=tab aria-controls=tab-description>
<a href=#tab-description>Beschreibung</a>
</li>
<li class=reviews_tab id=tab-title-reviews role=tab aria-controls=tab-reviews>
<a href=#tab-reviews>Fragen / Antworten</a>
</li>
</ul>