admin管理员组文章数量:1391937
Setting pointer-events:none
seems to also turn off touch events. This obviously doesn't make sense, because "touch" events aren't "pointer" events. My finger is not a pointer. :)
Is there some way to turn off only pointer/mouse events, but leave touch events alone? A property like touch-events
would be nice.
Setting pointer-events:none
seems to also turn off touch events. This obviously doesn't make sense, because "touch" events aren't "pointer" events. My finger is not a pointer. :)
Is there some way to turn off only pointer/mouse events, but leave touch events alone? A property like touch-events
would be nice.
2 Answers
Reset to default 5Actually, a touch event is a specific type of pointer event based on the definition.
From W3, Pointer Events, Section 1
A pointer can be any point of contact on the screen made by a mouse cursor, pen, touch (including multi-touch), or other pointing input device.
Also:
The events for handling generic pointer input look a lot like those for mouse: pointerdown, pointermove, pointerup, pointerover, pointerout, etc. This facilitates easier content migration from Mouse Events to Pointer Events. Pointer Events provide all the usual properties present in Mouse Events (client coordinates, target element, button states, etc.) in addition to new properties for other forms of input: pressure, contact geometry, tilt, etc. So authors can easily code to Pointer Events to share logic between different input types where it makes sense, and customize for a particular type of input only where necessary to get the best experience.
So, setting pointer-events:none;
will affect both touch and mouse events.
So to answer your question; you can't distinguish between mouse events
(I assume by pointer events
in your question you basically meant mouse events
) and touch events
with css only and the pointer-events
property. But since mouse events
and touch events
are different, you can revert to javascript for your needs in this case.
There is no way to disable only mouse events through CSS. But you can easily do it with javascript:
Check touch support by using Modernizr or simply see a discussion about touch detection How can I detect device touch support in JavaScript?
If touch events are not supported, apply a CSS class (you previously created) or directly add the CSS rule on all the elements you want to ignore pointer events.
本文标签: javascriptHow to eliminate pointer eventsbut not touch eventsStack Overflow
版权声明:本文标题:javascript - How to eliminate pointer events, but not touch events? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744756129a2623473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论