Created
September 29, 2017 20:22
-
-
Save jorgeinturias/f4dfbed32ed6932f66577ff8e38d9bdf to your computer and use it in GitHub Desktop.
Smooth scroll to anchor link (Internal & external pages)
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
jQuery(document).ready(function(){ | |
jQuery('a[href*=#]:not([href=#])').click(function() { | |
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') | |
|| location.hostname == this.hostname) { | |
var target = jQuery(this.hash); | |
target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']'); | |
if (target.length) { | |
jQuery('html, body').animate({ | |
scrollTop: target.offset().top - 90 }, 1000); | |
return false; | |
} | |
} | |
}); | |
}); | |
jQuery(window).load(function(){ | |
function goToByScroll(id){ | |
jQuery("html, body").animate({scrollTop: jQuery("#"+id).offset().top - 90 }, 1000); | |
} | |
if(window.location.hash != '') { | |
goToByScroll(window.location.hash.substr(1)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment