Reputation: 659
How do I automatically .scrollTo()
(using a plugin) when scrolling manually between two y positions? (if()
statement inside .scroll()
)
The code I have below, seems pretty straightforward. However, the scrolling is a bit bumpy and when it has scrolled automatically to the content, the scrolling is stuck there. As if it wants to do two things.
scrollToContent = function() {
$(document).stop(1, 1).scrollTo($('.content'), 750, { easing: 'easeInOutQuint' });
}
$(window).scroll(function() {
if ($(this).scrollTop() <= $(this).height()) {
scrollToContent();
}
});
Upvotes: 0
Views: 132
Reputation: 19750
This it too long for a comment, so I'm placing it as an answer instead. $(window).scroll()
is the method you want to use to check if the user is scrolling. If that messes with the scrollTo()
plugin, try setting flags. Eg:
var scrolling = false;
scrollToContent = function() {
scrolling = true;
// disable user scroll here
$(document).stop(1, 1).scrollTo($('.content'), 750, { easing: 'easeInOutQuint', onAfter: function() {
scrolling = false;
// reenable user scroll here
}});
}
$(window).scroll(function() {
if ($(this).scrollTop() <= $(this).height() && !scrolling) {
scrollToContent();
}
});
Upvotes: 2