Friday, January 22, 2016

Go to position with jQuery



This is just a small trick on how to go to the page section with Jquery by referenced from url. So the concept is not difficult first you need to do is to add the # which will be connected with your link (eg. www.url.com/page#id). After that you can use Jquery window.location.hash to get the "#id" from url. In this code I have used animate function to show the transition while the page is scrolled to the section.



ID


Text Description

$(function() {
        var ha = window.location.hash;
        if(ha) {
            var divLoc = $(ha).offset();
            $('html, body').animate({scrollTop: divLoc.top}, "slow");
        }
    })
 }
}



0 comments:

Post a Comment