July 27, 2010

Scroll to top - the new way

Thing you will find useful at some point - how to scroll from random part of page to the top ? Here's a way how to obtain it with jQuery :

$(document).ready(function(){
  $('a[href=#]').click(function(){
    $.scrollTo(0,'slow');
    return false;
  });
});

But remember to include jQuery ScrollTo plugin in your imports. Now every link with hash as target will scroll your page back to the top with nice jquerish effect. Cooll huh ?

No comments:

Post a Comment

stat4u