如何使用GWT和Chrome捕捉Zoom事件 [英] How to catch Zoom event with GWT and Chrome

查看:151
本文介绍了如何使用GWT和Chrome捕捉Zoom事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过关于如何在浏览器中获取当前缩放因子的大量讨论,但我还没有发现为什么这个片段在Firefox中,而不是在Chrome中。

  public class MyComposite extends Composite b $ b {
public MyComposite()
{
HTMLPanel panel = new HTMLPanel( <小程序> ...< /小程序>中);
panel.addDomHandler(new MouseWheelHandler()
{
@Override
public void onMouseWheel(MouseWheelEvent event)
{
event.stopPropagation();
event.preventDefault();
}
},MouseWheelEvent.getType());
initWidget(panel);






$ b在这两种浏览器中,该小程序,滚动不传播给父母(这很好)。当我在div外面滚动时,窗口会滚动(这也是正常的)。



但是当我做 + MouseWheel 时,在Firefox中,缩放事件被处理程序捕获并且不传播,而在Chrome中,处理程序似乎未被调用,并且事件随后被传播。我想停止在Chrome中传播。



Chrome中有错误还是我做错了?

最后的提醒:这似乎是Chrome中的一个错误。我提交了一份报告,但似乎并非如此他们的优先事项。如果你偶然发现这篇文章,并且你也想要这个功能,请在该报告中留言,也许它会加快速度......


I've seen there is much conversation about how to get the current zoom factor in the browser, but I haven't found out why this snippet works in Firefox, and not in Chrome.

public class MyComposite extends Composite
{
  public MyComposite()
  {
    HTMLPanel panel = new HTMLPanel("<applet>...</applet>");
    panel.addDomHandler(new MouseWheelHandler()
    {
        @Override
        public void onMouseWheel(MouseWheelEvent event)
        {
            event.stopPropagation();
            event.preventDefault();
        }
    }, MouseWheelEvent.getType());
    initWidget(panel);
  }
}

In both browsers, when I scroll inside the div containing the applet, the scroll is not propagated to the parent (which is fine). And when I scroll outside of the div, the window is scrolled (which is also fine).

But when I do Ctrl+MouseWheel, in Firefox the zoom event is caught by the handler and not propagated whereas in Chrome the handler seems not to be called, and the event is then propagated. I would like to stop the propagation in Chrome as well.

Is there a bug in Chrome or am I doing something wrong ?

解决方案

Late heads-up : this seems to be a bug in Chrome. I filed a report a couple of years ago but it seems not to be a priority for them. If you stumble upon this post and you want that "feature" too, please leave a message on that report, maybe it will speed up the things...

这篇关于如何使用GWT和Chrome捕捉Zoom事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆