Created
October 23, 2017 10:29
-
-
Save digamber89/d0a3d9de7f5f098c15ce13d5a31d12f2 to your computer and use it in GitHub Desktop.
Goto Scroll Smooth Animation
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
/* 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