JQuery - 我可以查询 MacBook Pro 触控板吗?
我可以使用 JQuery 查询触控板吗? 所以我可以做这样的事情:
Pseudo Javascript (JQuery)
$(document).keyInput().trackpadTwoFingersLeft(function() {
$('#div ul').animate({left: "=+1"},1);
});
有插件或其他框架可以做到这一点吗?
感谢您的每一个回复和想法。 :)
Can I use JQuery to query the Trackpad?
So I can do something like this:
Pseudo Javascript (JQuery)
$(document).keyInput().trackpadTwoFingersLeft(function() {
$('#div ul').animate({left: "=+1"},1);
});
Is there a plugIn or another framework where I can do this?
Thank you for every response and idea. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在网上浏览了一下,到目前为止发现 Chrome 和 Safari 都没有在浏览器中公开这些事件。
https://superuser.com/questions/27627/ Three- Finger-page-up-page-down-in-safari-chrome
可用的触摸事件在 Safari 中?
Firefox 确实支持某些内容:
https://developer.mozilla.org/ En/DOM/Mouse_gesture_events
但我没有看到很多对此的引用。
我想当只有一种浏览器支持时,使用这类事件有点没用。
I've looked around a bit on the web, and so far see that both Chrome and Safari do not expose these events in the browser.
https://superuser.com/questions/27627/three-finger-page-up-page-down-in-safari-chrome
Touch events available in Safari?
Firefox does support something:
https://developer.mozilla.org/En/DOM/Mouse_gesture_events
But I don't see a lot of references to this.
I guess when only one browser supports it, it is a bit useless to use these kind of events.
有一个 wheel 事件,您可以使用它来检测两个 - Mac 上手指滑动。
您的代码可能如下所示:
这可能无法在某些较旧的浏览器和/或 Mozilla 中工作(因为它会为滚轮运动触发一些不同的事件),但只要您将其实现为附加/辅助功能,此代码应该足够了。
There is a wheel event which you can use to detect two-finger swipe on Mac.
Your code could look something like this:
This could possibly not work in some older browser and/or Mozilla (as it fires some different event for the wheel movement), but as long as you implement this as an additional/helper feature, this code should suffice.
您可以使用鼠标滚轮跟踪来获得所需的效果: http:// www.switchonthecode.com/tutorials/javascript-tutorial-the-scroll-wheel
如果你想使用 jQuery,这个鼠标滚轮插件应该有帮助:http://brandonaaron.net/code/mousewheel/docs
You could probably use mouse wheel tracking to get the desired effect: http://www.switchonthecode.com/tutorials/javascript-tutorial-the-scroll-wheel
If you want to use jQuery, this mousewheel plugin should help: http://brandonaaron.net/code/mousewheel/docs
我们首先假设 OSX 机器有触控板,然后检测该用户是否插入了鼠标,从而设法确定触控板的使用情况。对不起,因为我们使用 typescript,但它可以在 javascript 中工作。
首先,只需查看用户代理属性,然后如果是 OSX,则假设它有一个。我只是在用户代理上使用一些基本的字符串表达式来确定操作系统是什么。
现在通过监听车轮事件来消除该设备。触控板设备将创建非常小的非整数 deltaY 值。我已经尝试过了,效果非常好。
现在使用触控板事件并检测通常不支持它的浏览器中的捏合(例如 HammerJS):
在 OSX Safari 和 iOS Safari 上,会触发“gesturestart”和“gesturechange”事件,这足以检测捏合和旋转。您可以使用缩放和旋转参数来获取所需的数据。
以下是一些可以帮助您入门的代码:
https:/ /medium.com/@auchenberg/detecting-multi-touch-trackpad-gestures-in-javascript-a2505babb10e
在 OSX Chrome 上,您可以使用“滚轮”事件来检测捏合、滚动和两根手指点击。您将看到的大多数解决方案都不支持 OSX Chrome 上的捏合或两根手指点击,但这个可以。以下是在 Chrome 上以及在所有其他浏览器上使用鼠标进行两指点击和捏合操作的方法:
We manage to determine trackpad usage by first assuming an OSX machine has it and then working to detect if that user has a mouse plugged in. Excuse me, because we use typescript, but it will work in javascript.
First, just look at the user agent properties, and then if OSX, assume it has one. I just use some basic string expressions on the user agent to determine what the OS is.
Now work to eliminate that device by listening to the wheel event. A trackpad device will create really small deltaY values that are non-integer. I have tried this and it does a very good job.
Now onto using trackpad events and detecting pinch in browsers that normally don't support it (HammerJS for example):
On OSX Safari and iOS Safari the "gesturestart" and "gesturechange" events are fired which are sufficient for detecting pinch and rotate. There are scale and rotate parameters you can use to get the data you need.
Here's some code to get you started:
https://medium.com/@auchenberg/detecting-multi-touch-trackpad-gestures-in-javascript-a2505babb10e
On OSX Chrome, you can use the "wheel" event to detect pinch, scroll, and two finger tap. Most solutions you'll see will not support pinch or two finiger tap on OSX Chrome, but this will. Here's how two finger tap and pinch are done for Chrome and also mice on all other browsers:
这里有一些信息,但我无法测试它
https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/SafariJSProgTopics/RespondingtoForceTouchEventsfromJavaScript.html#//apple_ref/doc/uid/TP40016162-SW6
There's some info here but I wasn't able to test it
https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/SafariJSProgTopics/RespondingtoForceTouchEventsfromJavaScript.html#//apple_ref/doc/uid/TP40016162-SW6