且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript/jquery中的触控板点击事件

更新时间:2022-02-11 08:56:34

我也遇到了同样的问题.看起来,例如MacBook上的触控板不会像实际的触摸设备那样触发TouchEvent.相反,它是将手势转换为MouseEvents.

I'm having this same concern. It appears that the trackpad on the MacBook (for example) doesn't fire TouchEvents like an actual touch device would. It is instead converting gestures into MouseEvents.

document.addEventListener('mousewheel', function(e) {
    console.log(e.wheelDelta);
});

document.addEventListener('touchstart', function(e) {
    console.log(e);
});

在上面的示例中,当我尝试在触控板上捕获捏/缩放"手势时,实际上是从滚轮上恢复了Delta,就像我按住CTRL然后向上或向下滚动一样,返回wheelDelta值120或-120.将事件侦听器用于"touchstart"不会像我所规定的那样写入控制台,除非它位于平板电脑或智能手机之类的触摸设备上.

In the above example, when I attempt to capture the "pinch/zoom" gesture on a trackpad, I'm actually getting back Delta from a scroll wheel as if I'd held down CTRL and then scrolled up or down, returning a wheelDelta value of 120 or -120. Putting event listeners on for 'touchstart' doesn't not write to the console as I prescribe unless it's on a touch device like a tablet or smart phone.

很明显,MackBook可以检测到您何时触摸了触控板,因为它可以检测到您的移动,但是似乎无法在文档中找到.

Obviously, the MackBook can detect when you've touched the trackpad since it's able to then detect your movement, but it does not appear to be available through the document.