Last active
December 19, 2015 01:39
-
-
Save jrstaatsiii/5877221 to your computer and use it in GitHub Desktop.
setTimeout to reconfigure the viewport
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
jQuery(document).ready(function($){ // so as to wait for any CSS-effecting assets to download | |
setTimeout(function() { // prepare the timeout | |
if(location.hash){ // is there a location hash? | |
if($(location.hash)){ // is there an element with an id that matches the location hash? | |
// determine the x location of the element we want to be in the viewport | |
var targetTop = $('#content').offset().top; | |
// accommodate the sticky element | |
targetTop -= $('#header').height() + $('#nav').height() - 23; | |
// force our scroll position based on what we want to show | |
$('body').scrollTop(targetTop); | |
} | |
} | |
}, 500); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment