Created
November 7, 2011 20:27
-
-
Save davist11/1346064 to your computer and use it in GitHub Desktop.
jQuery Tabs
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
;(function($) { | |
$.fn.tabs = function(options) { | |
return this.each(function() { | |
var tabs = {}; | |
tabs.init = function($base) { | |
var _this = this; | |
_this.$base = $base; | |
_this.$navTabs = _this.$base.find('.nav-tabs ul'); | |
_this.$tabContainer = _this.$base.find('.tabs'); | |
_this.$tabs = _this.$tabContainer.find('.tab'); | |
_this.$navTabs.on('click.tabs', 'a', _this.handleClick); | |
}; | |
tabs.handleClick = function(e) { | |
var _this = tabs, | |
$parent = $(this).parent(); | |
if(!$parent.hasClass('current')) { | |
_this.changeTab($parent); | |
} | |
e.preventDefault(); | |
}; | |
tabs.changeTab = function($linkParent) { | |
var _this = this, | |
newTab = $linkParent.index(); | |
//Toggle nav class | |
_this.$navTabs.find('.current').removeClass('current'); | |
$linkParent.addClass('current'); | |
//Change which tab is showing | |
_this.$tabs.filter('.current').fadeOut(150).removeClass('current'); | |
_this.$tabs.eq(newTab).fadeIn(250).addClass('current'); | |
}; | |
tabs.init($(this)); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment