Skip to content

Instantly share code, notes, and snippets.

@jsakhil
Last active March 17, 2020 12:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsakhil/2bad1268032ce048eeb204073eef6851 to your computer and use it in GitHub Desktop.
Save jsakhil/2bad1268032ce048eeb204073eef6851 to your computer and use it in GitHub Desktop.
Scroll to Div on page load
/* Function URL ScrollTo*/
function scrollto_div(uid){
jQuery('html, body').animate({
scrollTop: jQuery(uid).offset().top
}, 800);
}
/* Function URL ScrollTo*/
var hash = window.location.hash;
//anything else to do when window load
scrollto_div(hash);
/* SMOOTH SCROLL ON LOAD WHEN THE URL CONTAIN HASH */
$(document).on('click', 'a[href^="#"]', function (event) {
event.preventDefault();
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top
}, 800);
});
/* SMOOTH SCROLL ON LOAD WHEN THE URL CONTAIN HASH */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment