Disable scroll down with jQuery
2 answers
$('html, body').bind('DOMMouseScroll mousewheel MozMousePixelScroll', function(e) {
var scrollTo = 0;
if (e.type == 'mousewheel') {
scrollTo = (e.originalEvent.wheelDelta * -1);
}
else if (e.type == 'DOMMouseScroll') {
// scrollTo = 20 * e.originalEvent.detail; // turns out, this sometimes works better as expected...
scrollTo = e.originalEvent.detail;
}
if (scrollTo > 0) {
e.preventDefault();
return false;
}
});
+5
source to share
Following Alex's answer, I managed to do it like this:
$(window).on('DOMMouseScroll mousewheel MozMousePixelScroll', function(e) {
var direction = 0;
if (e.type == 'mousewheel') {
direction = (e.originalEvent.wheelDelta * -1);
} else if (e.type == 'DOMMouseScroll') {
direction = e.originalEvent.detail;
}
var divHeight = $("#myDiv").height();
var scrollTop = $(this).scrollTop();
if (direction > 0 && scrollTop > divHeight - window.innerHeight) {
e.preventDefault();
return false;
}
});
+1
source to share