Skip to content

Instantly share code, notes, and snippets.

@hemraj7171
Created January 9, 2017 04:55
Show Gist options
  • Save hemraj7171/00b5232ff53a8347f1ff26203936a2fe to your computer and use it in GitHub Desktop.
Save hemraj7171/00b5232ff53a8347f1ff26203936a2fe to your computer and use it in GitHub Desktop.
Scroll to specific page section according to url dynamically
/*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