Last active
May 5, 2019 10:53
-
-
Save GiuMagnani/e85e552dd2374d0f4cf3b278dd12e1aa to your computer and use it in GitHub Desktop.
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').on('click', function(e) { | |
smooth_scroll_to(this.hash, e); | |
}); | |
}); | |
jQuery(window).on('load',function() { | |
if(window.location.hash) { | |
smooth_scroll_to(window.location.hash); | |
} | |
}); | |
function smooth_scroll_to(hash, e) { | |
if(hash === '') { | |
return false; | |
} else { | |
if(jQuery(hash).length > 0) { | |
if(typeof e !== 'undefined') { | |
e.preventDefault(); | |
history.pushState(null, null, jQuery(e.target).attr('href')); | |
} | |
jQuery('html, body').animate({ | |
scrollTop: jQuery(hash).offset().top | |
}, 1500, 'swing'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment