I have a script like this:
$(document).ready(function(){
window.addEventListener('mousewheel', function(e){
e.preventDefault();
},{passive:false});
});
So now I need to make another function when on click of a button to override the above script and to "return" the default behavior.
I tested this:
$('#button').on('click', function(){
window.off('mousewheel');
});
And it's not working.
EDIT 2:
Just tested this and still not working:
$('#button').on('click', function(){
window.removeEventListener('mousewheel', function(e){
return true;
}, true);
});
Works Fine!
$(document).ready(function() {
function foo(e) {
console.log("mousewheel");
e.preventDefault();
}
window.addEventListener('mousewheel', foo, true);
$('#button').on('click', function() {
console.log("click");
window.removeEventListener('mousewheel', foo, true);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="button">Button</button>
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