Reputation: 31778
I would like to catch the onMouseWheel
event for the whole page (for context I am doing custom scrolling) but need to stop everything else on the page handling it too. How could this be done?
Thanks in advance.
Upvotes: 1
Views: 69
Reputation: 36000
You should call
event.preventDefault();
after processing the event.
Like this:
window.addEventListener("onMouseWheel", function(event) {
// process the event for custom scrolling
event.preventDefault();
event.stopPropagation();
}, true);
Upvotes: 2
Reputation: 2271
You can do it in jquery like this:
$(function(){
$('*:not(body)').on('mousewheel',function(e){
e.preventDefault();
e.stopPropagation();
});
});
Alternate solution using pure javascript:
var ele = document.querySelectorAll('*:not(body)');
ele.forEach(function(i){
ele[i].addEventListener('mousewheel',function(e){
e.preventDefault();
e.stopPropagation();
},false);
});
Upvotes: 0