Shniper
Shniper

Reputation: 854

Using .scrollTo() to scroll to a section

I'm trying to use .scrollTo in jquery to scroll to another section based on if the scroll direction was up or down. I have the scrollTo source code in the example but the scroll is still scrolling regularly.

DEMO

var lastScrollTop = 0;
$(window).scroll(function(event){
   var st = $(this).scrollTop();
   if (st > lastScrollTop){
      $('body').scrollTo('.one');
   } else {
      $('body'.scrollTo('.two');
   }
   lastScrollTop = st;
});

Upvotes: 1

Views: 210

Answers (1)

Moseleyi
Moseleyi

Reputation: 2859

Have you tried:

$("body").stop().animate({
    scrollTop : $(".one").offset().top
});

(offset may need to be changed to position depending on your site)

-edit: added .stop(), which will stop animation overlap

Upvotes: 2

Related Questions