Skip to content

Instantly share code, notes, and snippets.

@gearmobile
Created May 28, 2015 18:28
Show Gist options
  • Save gearmobile/f476d5f17562a8cbe352 to your computer and use it in GitHub Desktop.
Save gearmobile/f476d5f17562a8cbe352 to your computer and use it in GitHub Desktop.
jQuery Tabs
HTML:
<div class="wrapper">
<div class="tabs">
<span class="tab">Вкладка 1</span>
<span class="tab">Вкладка 2</span>
<span class="tab">Вкладка 3</span>
</div>
<div class="tab_content">
<div class="tab_item">Содержимое 1</div>
<div class="tab_item">Содержимое 2</div>
<div class="tab_item">Содержимое 3</div>
</div>
</div>
CSS:
/* Убираем табы без JS */
.wrapper .tab {
display: none;
}
.wrapper .active {
color: red;
}
JS:
$(".tab_item").not(":first").hide();
$(".wrapper .tab").show().click(function() {
var ind = $(this).index();
$(".wrapper .tab").removeClass("active").eq(ind).addClass("active");
$(".tab_item").hide().eq(ind).fadeIn()
}).eq(0).addClass("active");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment