Scroll To - A simple way to animate to anchors

Scroll To provides a simple way to animate to anchors.

Scrolling to a spot in an HTML page is pretty simple to do with JQuery, but if you have a lot of IDs on the page to scroll to, the code can get a little messy. This plugin solves that by allowing you to write your anchor tags just as you normally would with the href attribute pointed at the ID you would like to move to (e.g. href="#importantSection".) This means that if JavaScript is turned off, your site will continue to function normally. You can offset the location of where you scroll to, control the speed and override the element ID you are scrolling to all through the plugin.

<a href="#spotToGoTo" id="selector">Click Here</a>

The plugin will still set the hash value (i.e. #anchorPoint) like normal so you can still deep link into your page, however for browsers that do not supporthistory.pushState, there may be issues with using offset. This is because for those browsers, you cannot stop the window from firing the onHashChange event, which will then jump to the exact location. If you're not using offset however, everything will work normally.

 

w10schools
2014-08-04 08:00:35
Comments
Leave a Comment

Please login to continue.