Is it possible to stop event propagation without preventing the default event behaviour?
This should let the input increment/decrement when scrolled but stop it from bubbling to any other elements and scrolling the outer div. (The following is Chrome-only, I think)
$("input[type=number]").on("mousewheel",function(e){ // only works with chrome I think
e.stopPropagation();
console.log("scrolled");
});
div{
height:50px;
overflow:auto;
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div>
<input type='number'>
<div class='filler'></div>
</div>
But the stopPropagation
call seemingly does nothing. The outer div still scrolls.
Now, this particular issue (scrolling a number input) can be solved by preventingDefault
and manually incrementing and decrementing the input (JSFiddle).
I'm looking for a general solution that doesn't involve re-creating the default behaviour.