How can scroll be prevented after scrollTop reaches certain value say 150.
$(window).scroll(function() {
if($(window).scrollTop() >=50)) {
return false; // basically don't scroll
}
});
the .scrollTop
set the scrollHeight using scrollTo
function. It doesn't scroll from x to y, It just goes to y.
So basically you cannot stop the scroll as your event will be called after it is set to y. You can probably set the desired scrollHeight
inside the handler after comparing the height.
if($(window).scrollTop() >=50)
{
$(window).scrollTop(0);
}
Note: using it on an element is bearable, but on window object will be annoying to the user. Above is just to show how it works.
Try scrolling in >> http://jsfiddle.net/KwgMj << and see how annoying it can be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With