在 jQuery 中处理移动 Web 的 mouseover/mouseout 事件
我正在开发移动网络,并面临 js 中使用的 mouseover
/mouseout
事件的问题。这两个事件用于更改链接的不透明度。问题是,我需要点击两次(在 iPhone 上测试)才能激活链接。我的猜测是,第一次点击时,它将点击视为鼠标悬停事件,第二次点击视为点击事件。
有什么方法可以跳过/禁用/忽略移动网络的这些事件,这样我就不需要点击两次?
谢谢
I am working on mobile web and facing problem with mouseover
/mouseout
events used in js. These two events are used to change opacity of links. The problem is, I need to tap twice (testing on iPhone) to activate the link. My guess is, on first tap it consider the tap as mouseover
event and second tap as click event.
Is there any way I can skip/disable/ignore these events for mobile web, so I don't need to tap twice?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个迟到的回应,但为了后代和任何谷歌搜索的人,这里有一个解决方案:
不要使用 .mouseenter(),而是使用 .mousemove()。您可以保留 mouseleave(),因为在您单击移动设备上的项目后,这并不重要。 .mousemove() 被忽略,并且在第一次触摸时触发单击。
您可能想要绑定/取消绑定事件,以便它仅触发一次。
http://api.jquery.com/mousemove/
This is a late response, but for the sake of posterity and anyone googling here's a solution:
Instead of using .mouseenter(), use .mousemove(). You can leave mouseleave() as this is inconsequential after you click on an item on a mobile device. .mousemove() is ignored, and the click is triggered on the first touch.
You might want to bind / unbind the event so it triggers only once.
http://api.jquery.com/mousemove/
根据您的服务器端设置,也许您可以使用用户代理检测 - 可能特别是用户代理检测的 UAProf 元素,为特定设备提供 javascript 服务?
这将允许您以多种不同的方式满足移动设备的需求 - 这将有助于您可能希望使用的任何其他“over”事件行为 - 基于鼠标悬停等扩展 div。
如果您搜索用户代理检测 - 希望这有帮助。
Depending on your server-side set up, perhaps you could use user agent detection - and probably specifically the UAProf element of User Agent Detection, to serve javascript for specific devices?
This would allow you to cater for mobile devices in a number of different ways - this would help with any other 'over' event behaviour you may look to use - expanding a div based on mouseover etc.
There's a lot of information available already if you search for user agent detection - hope this helps.
您查看过 jQuery Mobile 吗?这可以解决移动应用程序中许多与鼠标相关的问题。
Did you take look at jQuery Mobile? This could solve a lot of mouse-related issues in a mobile app.