Last active
March 17, 2020 12:38
-
-
Save jsakhil/2bad1268032ce048eeb204073eef6851 to your computer and use it in GitHub Desktop.
Scroll to Div on page load
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
/* 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