Created
July 2, 2012 17:41
-
-
Save renie/3034515 to your computer and use it in GitHub Desktop.
Just the logic, with jquery, for a tab menu( I will convert this in a plugin and improve logic )( WITHOUT STYLE! Stylish by yourself )
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
$(document).ready(function(){ | |
//if exists a tab menu | |
if($('.tabsMenu').length > 0){ | |
prepareTabMenu(); | |
} | |
}); | |
/** | |
* Prepare elements with function that will be called when clicked | |
* */ | |
var prepareTabMenu = function(){ | |
$('.tabsMenu li a').bind('click', function(){ | |
var tab = $(this).attr('id').split("-"); | |
changeTabSelected(this, tab[1]); | |
return false; | |
}); | |
selectStartTabMenu(); | |
return false; | |
}; | |
/** | |
* Show tab content of selected menuTab | |
*/ | |
var changeTabSelected = function(clicked, tab){ | |
tab = "#tabcontent-" + tab; | |
if(!$(tab).hasClass('active')){ | |
$('.tabsMenu li .active').removeClass('active'); | |
$('.tabContent.active').removeClass('active'); | |
$('.tabContent').hide(); | |
$(tab).show(); | |
$(tab).addClass('active'); | |
$(clicked).addClass('active'); | |
return false; | |
} | |
return false; | |
} | |
/** | |
* Open tab has menu active ( JUST ONE TAB CAN BE SELECTED ) | |
*/ | |
var selectStartTabMenu = function(){ | |
var clicked = $('.tabsMenu li .active'); | |
var tab = $('.tabsMenu li .active').attr('id').split("-"); | |
changeTabSelected(clicked, tab[1]); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment