开发者

Deal with mouseover/mouseout event in jQuery for mobile web

开发者 https://www.devze.com 2023-03-14 22:46 出处:网络
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) t

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 secon开发者_高级运维d 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


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/


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.


Did you take look at jQuery Mobile? This could solve a lot of mouse-related issues in a mobile app.

0

精彩评论

暂无评论...
验证码 换一张
取 消