Anchor links fix

This commit is contained in:
John Mulhausen 2017-03-02 04:37:13 -08:00
parent 910dd4c588
commit 02bb0de07d
1 changed files with 12 additions and 8 deletions

View File

@ -175,6 +175,14 @@ $(document.body).scrollspy({
offset: navHeight offset: navHeight
}); });
function loadHash(hashObj)
{
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hashObj).offset().top-80
}, 800);
}
$(document).ready(function(){ $(document).ready(function(){
// Add smooth scrolling to all links // Add smooth scrolling to all links
@ -188,18 +196,14 @@ $(document).ready(function(){
// Store hash // Store hash
var hash = this.hash; var hash = this.hash;
loadHash(hash);
// Using jQuery's animate() method to add smooth page scroll // Add hash (#) to URL when done scrolling (default click behavior)
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area window.location.hash = hash;
$('html, body').animate({
scrollTop: $(hash).offset().top-80
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if } // End if
}); });
if (window.location.hash) loadHash(window.location.hash);
}); });