Question

I need some help. I am trying to bind to the mousewheel event from JavaScript and I've successfully done that. But something doesn't work quite as I expected. When I am over an input the event doesn't fire.

I have tried to bind to the input's event for the mousewheel but the same thing happens, the event doesn't fire.

Was it helpful?

Solution

This event is not universally supported. Check mousewheel compatibility table before anything. What I find interesting is that javaScript libraries like jQuery didn't implemented wrappers for this particular event. If you plan to use jQuery people build plugins for this:

UPDATE

You have to modify a little their example. Here, this works

$(document).ready( function(){
    $('#inputTest').bind('mousewheel', function(event, delta) {
        var dir = delta > 0 ? 'Up' : 'Down', vel = Math.abs(delta);
        $(this).val(dir + ' at a velocity of ' + vel);
        return false;
    });
});

HTML code

<form>
    <input type='text' name='inputTest' id='inputTest' />
</form>

For an input field use val() instead of text().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top