Skip to content

Instantly share code, notes, and snippets.

@digamber89
Created October 23, 2017 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digamber89/d0a3d9de7f5f098c15ce13d5a31d12f2 to your computer and use it in GitHub Desktop.
Save digamber89/d0a3d9de7f5f098c15ce13d5a31d12f2 to your computer and use it in GitHub Desktop.
Goto Scroll Smooth Animation
/* requires jquery */
jQuery(function($){
var jump = function(e) {
if(e){
e.preventDefault();
var href = $(this).attr("href");
var hashvalue = '';
if( href.length != 0){
var site_url = href.split('#')[0];
hashvalue = href.substr(href.indexOf("#"));
target = hashvalue.substr(0, hashvalue.indexOf('-'));
//site_url needs to be sent as localized value
window.location = site_url + target + '-goto';
}
} else {
hashvalue = location.hash;
target = hashvalue.substr(0, hashvalue.indexOf('-'));
}
if( $(target).length != 0){
$('html,body').animate({
scrollTop: $(target).offset().top - 120
}, 1000, function() {
location.hash = hashvalue;
});
}
};
$('a[href*="#"]:not([href="#"])').bind("click", jump);
$(window).on('load', function(e){
if (location.hash){
jump();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment