iPad/iPhone hover problem causes the user to double click a link

后端 未结 26 1752
太阳男子
太阳男子 2020-11-27 09:18

I have some websites I built times ago, that use jquery mouse events...I just got an ipad and i noticed that all the mouse over events are translated in clicks...so for inst

26条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 09:51

    Seems there is a CSS solution after all. The reason Safari waits for a second touch is because of the background image (or elements) you usually assign on the :hover event. If there is none to be shown - you won't have any problems. The solution is to target iOS platform with secondary CSS file (or style in case of a JS approach) which overrides :hover background to inherit for example and keep hidden the elements you were going to display on mouse over:

    Here is an example CSS and HTML - a product block with a starred label on mouse over:

    HTML:

    Some text here
    

    CSS:

    .s {
       background: url(some-image.png) no-repeat 0 0;
    
    }
    .s:hover {
       background: url(some-image-r.png) no-repeat 0 0;
    }
    
    .s-star {
       background: url(star.png) no-repeat 0 0;
       height: 56px;
       position: absolute;
       width: 72px;
       display:none;
    }
    
    .s:hover .s-star {
       display:block;
    }
    

    Solution (secondary CSS):

    /* CSS */
    /* Keep hovers the same or hidden */
    .s:hover {
       background:inherit;
    }
    .s:hover .s-star {
       display:none;
    }
    

提交回复
热议问题