Created
January 9, 2017 04:55
-
-
Save hemraj7171/00b5232ff53a8347f1ff26203936a2fe to your computer and use it in GitHub Desktop.
Scroll to specific page section according to url dynamically
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
/*Scroll down specific section when page load*/ | |
//render current page URL | |
var uri = window.location.toString(); | |
// if URL contain '#' | |
if (uri.indexOf("#") > 0) { | |
//save '#' url | |
var hashValue = location.hash; | |
//remove '#' url for cleaning | |
// not necessary | |
var clean_uri = uri.substring(0, uri.indexOf("#")); | |
window.history.replaceState({}, document.title, clean_uri); | |
//scroll to specific section comes form # URL | |
setTimeout(function(){ | |
$('html,body').animate({ | |
scrollTop: $(hashValue).offset().top-70 | |
}, 1000); | |
},200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment