Posted By

Pjotor on 11/15/14


Tagged

plugin navigation jquery scrolling ui


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jdiprose
JeffSFO


scrollTo


 / Published in: JavaScript
 

URL: http://pjotor.com

$(selector).scrollTo( [DURATION][,EASING][,CALLBACK])

  1. (function ($) {
  2. $.fn.scrollTo = function (speed, easing, callback) {
  3. $('body').animate({
  4. scrollTop: this.offset().top
  5. }, speed, easing, callback);
  6. return this;
  7. };
  8. }(jQuery));

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Pjotor on January 9, 2015

(function ($) { $.fn.scrollTo = function (speed, easing, callback) { $('html, body').stop().animate({ scrollTop: this.offset().top }, speed, easing, callback); return this; };

$('a[href^="#"]').on('click.scrollTo',function (e) {
    e.preventDefault(); var anchor = this.hash;
    $('[name='+anchor.substr(1)+'], ' + anchor)
    .scrollTo(400,  function(){ 
        window.location.hash = anchor; 
    });
});    

}(jQuery));

You need to login to post a comment.