How do I simulate a hover with a touch in touch enabled browsers?

后端 未结 14 2098
旧巷少年郎
旧巷少年郎 2020-11-22 17:04

With some HTML like this:

Some Text

Then some CSS like this:

p {
  color:black;
}

p:hover {
  color:red         


        
14条回答
  •  星月不相逢
    2020-11-22 17:25

    All you need to do is bind touchstart on a parent. Something like this will work:

    $('body').on('touchstart', function() {});
    

    You don't need to do anything in the function, leave it empty. This will be enough to get hovers on touch, so a touch behaves more like :hover and less like :active. iOS magic.

提交回复
热议问题