views:

445

answers:

1

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.

+1  A: 

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().

Elzo Valugi
That's exactly the plugin I am using.
Christian Toma
Later on I'll try to make a test to see how this plugin is working. Meanwhile, if you are trying to change a value in an input field through scrolling take a look at this plugin http://plugins.jquery.com/project/spin-button.
Elzo Valugi
No that's not what I'm trying to do at all, I just want the mousewheel event to fire when I am over the text field.
Christian Toma
Check the updates.
Elzo Valugi