Created
December 1, 2009 09:42
-
-
Save evilstreak/246187 to your computer and use it in GitHub Desktop.
Simple tabs code for thinjs
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
$( ".tabs" ).each( function() { | |
// a collection of all the tabs for closing over | |
var tabs = []; | |
// find all the anchor links inside | |
$( "a[href^='#']", this ).each( function() { | |
// find the element this anchor targets and stash it | |
var href = this.href.substring( this.href.lastIndexOf( "#" ) ), | |
tab = $( href )[ 0 ]; | |
tabs.push( tab ); | |
// hide it | |
tab.style.display = "none"; | |
// add a click event to the anchor to reveal the target | |
$( this ).bind( "click", function() { | |
$( tabs ).each( function() { | |
this.style.display = "none"; | |
} ); | |
tab.style.display = "block"; | |
} ); | |
} ); | |
// see if a certain tab should be pre-selected (bash on the current hash) | |
if ( location.hash && $( location.hash ).length ) { | |
$( location.hash )[ 0 ].style.display = "block"; | |
} | |
// otherwise reveal the first tab | |
else { | |
tabs[ 0 ].style.display = "block"; | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment