Fix CSS hover on iPhone/iPad/iPod

前端 未结 16 570
星月不相逢
星月不相逢 2020-12-02 14:53

I want to fix the hover effect on iOS ( change to touch event ) but I dont have any idea . Let me explain this . You have a text in your page :

相关标签:
16条回答
  • 2020-12-02 15:15

    Add onclick="" to anything you wish iOS to recognise as an element with a hover.

    <div onclick="">Click Me!</div>
    
    0 讨论(0)
  • 2020-12-02 15:17

    On some sites I need to use css "cursor:help". Only iOS it gave me a lot of irritation. To solve this, change everything af the page to "cursor:pointer". That works for me.

    jQuery:

    if (/iP(hone|od|ad)/.test(navigator.platform)) {
    $("*").css({"cursor":"pointer"});
    }
    
    0 讨论(0)
  • 2020-12-02 15:18
    1. Assigning an event listener to the target element seems to work. (Works with 'click', at least.) CSS hover on ios works only if an event listener is assigned

    2. Wrapping the target element in an a[href=trivial] also seems to work. https://stackoverflow.com/a/28792519/1378390

    A related note/diagram on mobile Safari's algorithm for handling clicks and other events is here: Is it possible to force ignore the :hover pseudoclass for iPhone/iPad users?

    0 讨论(0)
  • 2020-12-02 15:20

    In response to Dan (https://stackoverflow.com/a/20048559/4298604), I would recommend a slightly altered version.

    <div onclick="void(0)">Click Me!</div>

    Adding "void(0)" helps to obtain the undefined primitive value, as opposed to "".

    0 讨论(0)
提交回复
热议问题