Is there any way to disable only scroll down in jQuery?
Thank you very much in advance
Is there any way to disable only scroll down in jQuery?
Thank you very much in advance
$('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;
}
});
Following Alex's answer, I managed to do it in the next way:
$(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;
}
});