Created
September 27, 2013 20:55
-
-
Save jakepruitt/6735009 to your computer and use it in GitHub Desktop.
A quick gist for a code demo
This file contains hidden or 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
| <div id="ctl11_ctl00_MainNavRepeater_ctl01_SubMenuPanel" class="subnav"> | |
| <ul class="clearfix" style="text-align: left;"> | |
| <li style="margin-left: 101px;"><a href="/business-aviation/featured-products">Featured Products</a></li> | |
| <li ><a href="/business-aviation/platforms">Platforms</a></li> | |
| <li ><a href="/business-aviation/transform-your-aircraft">Transform Your Aircraft</a></li> | |
| </ul> | |
| </div> |
This file contains hidden or 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
| // define browser width and subtract extra width from main nav | |
| var browserWidth = $(window).width(); | |
| var mainNavWidth = $("#main_nav ul").innerWidth(); | |
| var extraWidth = (browserWidth - mainNavWidth)/2; | |
| // find the active button left orientation | |
| var activeButtonLeft = $("#main_nav li.active").position().left; | |
| activeButtonLeft = activeButtonLeft - extraWidth; | |
| // find the active button center orientation - to help center subnav under it | |
| var activeButtonWidth = $("#main_nav li.active").width(); | |
| var activeButtonCenter = activeButtonLeft + (activeButtonWidth / 2); | |
| // calculate the subnav width | |
| var subNavWidth = 0; | |
| $('#main_nav div.subnav ul li').each(function() { | |
| subNavWidth += $(this).outerWidth(); | |
| }); | |
| // determine sub nav center | |
| var subNavLeft = activeButtonCenter - (subNavWidth/2); | |
| // make adjustments to align subnav centered under active main nav button, or right or left if need be | |
| if (activeButtonLeft == 0) { | |
| $('#main_nav div.subnav ul').css("text-align", "left"); | |
| $('#main_nav div.subnav ul').css("padding-left", "28px"); | |
| } else if (activeButtonLeft > 750) { | |
| $('#main_nav div.subnav ul').css("text-align", "right"); | |
| $('#main_nav div.subnav ul').css("padding-right", "50px") | |
| } else { | |
| $('#main_nav div.subnav ul').css("text-align", "left"); | |
| $('#main_nav div.subnav ul li:first-child').css("margin-left", subNavLeft); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment