HTML5 event listener for number input scroll - Chrome only(数字输入滚动的 HTML5 事件监听器 - 仅限 Chrome)
问题描述
我正在玩一些 HTML5 元素,并遇到了一个有趣的行为.这仅适用于 Chrome.
I'm playing around with some HTML5 elements, and ran into a fun behavior. This only works in Chrome.
使用数字输入类型,您可以设置最小值、最大值和步长,并通过上下箭头来控制输入.<input type="number" min="0" max="100" step="5"/>
Using an input type of number, you can set the min, max, and step, and get up and down arrows to control the input. <input type="number" min="0" max="100" step="5" />
我发现绑定单击事件侦听器会捕获箭头上的按下,因为在字段模糊之前不会真正发生更改.您还可以使用键盘上的向上和向下箭头键在限制范围内更改值,并且按键绑定可以获取这些值.
I've found that binding a click event listener captures presses on the arrows, as a change won't actually occur until the field is blurred. You can also use the up and down arrow keys on your keyboard to change the value within the limits, and a keypress bind can pick these up.
但是,在 Chrome 中,您也可以使用鼠标滚轮来更改输入,方法是将鼠标悬停在输入上并滚动.但是,我一直无法找到监听此事件的方法.
In Chrome, however, you can also use your mouse wheel to change the input, by hovering over the input and scrolling. I have not been able to find a way to listen for this event, however.
jsfiddle 示例
HTML:
<input type="number" min="0" max="100" step="5" id="test" />
JavaScript(使用 jQuery):
JavaScript (using jQuery):
$( '#test' ).click(function(){
$( this ).after( '<br />click' );
});
$( '#test' ).change(function(){
$( this ).after( '<br />change' );
});
$( '#test' ).keypress(function(){
$( this ).after( '<br />keypress' );
});
关于如何监听滚动变化的任何想法?同样,在撰写本文时,这仅适用于 Chrome.
Any ideas on how to listen for that scroll change? Again, this only works in Chrome as of this writing.
推荐答案
jQuery 鼠标滚轮插件似乎可以解决问题.http://plugins.jquery.com/project/mousewheel
The jQuery Mouse Wheel plugin seems to do the trick. http://plugins.jquery.com/project/mousewheel
$( '#test' ).mousewheel(function(){
$( this ).after( '<br />mouse wheel' );
});
这篇关于数字输入滚动的 HTML5 事件监听器 - 仅限 Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:数字输入滚动的 HTML5 事件监听器 - 仅限 Chrome
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01