Reputation: 854
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.
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
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