Created
February 4, 2016 10:32
-
-
Save manabuyasuda/bcf72f248f609636200b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// タブリスト | |
// `.index(this)`でクリックされた`li`のインデックスを取得して変数に格納。 | |
// `.eq()`でインデックスを渡す。 | |
// `return false;`でアンカータグを無効化する。 | |
$(function(){ | |
var $tabList = $('.tabList').find('li'); | |
var $tabBody = $('.tabBody').find('li'); | |
var state = 'is-active'; | |
$tabList.click(function() { | |
var $index = $tabList.index(this); | |
$tabList.removeClass(state); | |
$tabBody.removeClass(state); | |
$(this).addClass(state); | |
$tabBody.eq($index).addClass(state); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment