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.
我需要一些帮助。我试图从JavaScript绑定到mousewheel事件,我已成功完成。但事情并不像我预期的那样有效。当我在输入时,事件不会触发。
I have tried to bind to the input's event for the mousewheel but the same thing happens, the event doesn't fire.
我试图绑定到鼠标滚轮的输入事件,但同样的事情发生,事件不会触发。
1 个解决方案
#1
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:
此事件不受普遍支持。事先检查鼠标滚轮兼容性表。我觉得有趣的是像jQuery这样的javaScript库没有为这个特定事件实现包装器。如果你打算使用jQuery人为此构建插件:
- Mouse Wheel Plugin
鼠标滚轮插件
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().
对于输入字段,请使用val()而不是text()。
#1
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:
此事件不受普遍支持。事先检查鼠标滚轮兼容性表。我觉得有趣的是像jQuery这样的javaScript库没有为这个特定事件实现包装器。如果你打算使用jQuery人为此构建插件:
- Mouse Wheel Plugin
鼠标滚轮插件
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().
对于输入字段,请使用val()而不是text()。