捕捉Mac触控板变焦 [英] Catching Mac trackpad zoom

查看:93
本文介绍了捕捉Mac触控板变焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在我的应用程序中,我捕捉鼠标滚轮事件并在Canvas元素上执行放大或缩小操作。如果用户使用Mac并尝试使用触控板执行缩放,则没有事件,实际发生的是放大/缩小浏览器。



有没有办法捕获使用触控板执行缩放事件?

解决方案

至少在Chrome中,触控板捏到缩放触发轮/鼠标滚轮事件,就像按下了ctrl键一样。您可以像任何其他wheel / mousewheel事件一样捕获此事件,并防止其发生默认情况。这里是一个使用jQuery的例子:
$ b $ $ $ $ $ $ $ $ $ $ $ $ $(canvas)。on(mousewheel,function(e){
if(e.ctrlKey){
e.preventDefault();
e.stopImmediatePropagation();

//在这里执行所需的缩放操作
}
});


Currently in my application i am catching the mouse wheel events and perform zoom in or out on a Canvas element. If user uses Mac and tries to perform zoom with the trackpad, there is no event and what actually happens is zoom in/out of browser.

Is there a way to catch the zoom event performed with the trackpad?

解决方案

At least in Chrome, trackpad "pinch-to-zoom" triggers a wheel/mousewheel event that appears as though the ctrl key is pressed. You can capture this event just like any other wheel/mousewheel event and prevent its default from occurring. Here is an example using jQuery:

$("canvas").on("mousewheel", function(e) {
    if (e.ctrlKey) {
        e.preventDefault();
        e.stopImmediatePropagation();

        // perform desired zoom action here
    }
});

这篇关于捕捉Mac触控板变焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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