GWT MouseWheelHandler 在 Firefox 中不起作用
我正在尝试制作一个文本框,当有人时它会改变值 将鼠标滚轮滚动到其上。 具体来说,我的目标是 文本框中的数字在向上滚动时增加,在向上滚动时减少 我向下滚动。 但是,我很难弄清楚 鼠标滚轮处理程序。 我简化了代码,只需将值更改为 “向上”或“向下”,但就是不起作用。 但它可以编译。 我也 用 event.preventDefault() 尝试过,但这似乎没有任何作用 影响。
private TextBox valueField = new TextBox();
...
...
valueField.addMouseWheelHandler(new MouseWheelHandler() {
public void onMouseWheel(MouseWheelEvent event) {
//event.preventDefault();
if(event.isNorth()) {
valueField.setText("UP");
} else {
valueField.setText("DOWN");
}
}
});
编辑:我刚刚在 Chromium 和 Opera 中测试了它,效果很好。 不幸的是,它仍然无法在我的支持的浏览器(Firefox 和 IE)中运行。
编辑:决定尝试原生 Javascript 方法。 我的 Javascript 技能很弱,所以我仍然需要一些帮助。
I'm trying to make a TextBox that will change value when someone
scrolls the mouse wheel over it. Specifically, my goal is for the
number in the text box to increase when i scroll up, and decrease when
i scroll down. However, I'm having trouble figuring out the
MouseWheelHandler. I simplified my code to just change the value to
"UP" or "DOWN", but it just doesn't work. It compiles though. I also
tried it with event.preventDefault(), but that didn't seem to have any
effect.
private TextBox valueField = new TextBox();
...
...
valueField.addMouseWheelHandler(new MouseWheelHandler() {
public void onMouseWheel(MouseWheelEvent event) {
//event.preventDefault();
if(event.isNorth()) {
valueField.setText("UP");
} else {
valueField.setText("DOWN");
}
}
});
Edit: I just tested it in Chromium and Opera, and it worked fine. Unfortunately, it still does not work in my supported browsers (Firefox and IE).
Edit: Decided to try a native Javascript method. My Javascript skills are weak, so I still need some help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将尝试使用原生 Javascript 方法来解决这个问题。 我让这个工作。
现在我正在寻找一种将 DOMMouseScroll 侦听器添加到元素本身的方法。 这是否可能,或者我应该在用户将鼠标悬停在元素上时为窗口创建一个 DOMMouseScroll 侦听器? 另外,如何防止窗口滚动?
I'm going to try to solve this problem with a native Javascript method. I got this to work.
Now I'm looking for a way to add a DOMMouseScroll listener to the element itself. Is this possible, or should I just create a DOMMouseScroll listener for the window whenever a user mouses over the element? Also how do I prevent the window from scrolling?
我使用本机方法在 Firefox 下成功运行了该方法,当文本框触发鼠标悬停事件时,该方法将鼠标滚轮侦听器添加到窗口。
编写此方法后不久,我了解到 GWT 的最新 svn 修订版已修复了 Firefox 的 MouseWheelEvent。 然而,我已经写好了这篇文章,而且我不想下载不稳定的版本,所以我将保留它直到下一个稳定的 GWT 版本。
I got this successfully running under Firefox using a native method that adds a mouse wheel listener to the window when the text box fires a mouseover event.
Shortly after writing this method, I learned that the latest svn revisions of GWT have fixed the MouseWheelEvent for Firefox. However, I've already got this written, and I don't feel like downloading an unstable release, so I'll keep this until the next stable GWT release.