hover event on touch device

2020-04-20 04:56发布

I decrease opacity of <ul> when mouse over the <ul> tag area and then set full opacity for <li> which user is on that.

like this sample: Image change opacity on hover without jQuery

now, the problem is in tablet and phones, because on touch devices we don't have hover event and user should click (touch) on <li> so all another <li> will decrease the opacity and user cannot unselect (unhover) that <li> so they should refresh the page.

How can I solve this problem?

标签: html css
3条回答
▲ chillily
2楼-- · 2020-04-20 05:16

Since :hover is of course not supported in touch only browsers, you can use the touchStart, touchMove, and touchEnd events (through javascript). These are used very well in the FastClick library.

Also some CSS :hover events can be activated through a touch only browser if you hold your finger on the screen.

查看更多
祖国的老花朵
3楼-- · 2020-04-20 05:35

On touch devices, hover is not supported. You can either:

• skip hover effects in touch device stylesheets
• use JavaScript to turn hover into click interactions
• use JavaScript to simulate hover interactions on the touch device

There are multiple other posts on SO that discuss about this problem:

How do I simulate a hover with a touch in touch enabled browsers?
how to deal with hover effect on touch devices
Hover for Touch Devices

查看更多
Deceive 欺骗
4楼-- · 2020-04-20 05:38

A bit late...

but you could use css animations to show the menu for 4-5 seconds before hiding it again...

not perfect but you get rid of the JS .. not that js is wrong, i use angularJS..

EDIT: -- were asked to ref hers a link http://www.greywyvern.com/?post=337

查看更多
登录 后发表回答