how to deal with hover effect on touch devices

孤人 提交于 2020-01-11 04:19:07

问题


i have following code

<div>
    <img src="http://placehold.it/350x150"/>
    <div class="link-cont"><a href="#">click here to see more info</a></div>

</div>


div {
    width: 350px;
    font-size:12px;
    position: relative;    
}
div img{
    padding:0 10px;    
}
.link-cont {
    background: red;
    position: absolute;
    bottom: 0;
    width: 370px;
    height: 210px; 
    opacity: 0;
    transition: all 0.4s;
    z-index: -1
}
div:hover  .link-cont {
    opacity: 1; 
    bottom:-40px;
}
.link-cont a{    
    opacity: 0;  
}
div:hover  .link-cont a{
    position: relative; 
    opacity: 1; 
    bottom:-175px;
    left:10px;
    background:#fff;
    color:red;
    text-decoration:none;
    padding:0 10px;
}

A link is wrapped inside a div which appears on hover. how do i make this touch device friendly.

jsfidd--> http://jsfiddle.net/yeyene/Nnd7w/17/


回答1:


Several solutions:

  • 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 (see this Question on StackOverflow



回答2:


Try this:

<script>
document.addEventListener("touchstart", function(){}, true);
</script>


来源:https://stackoverflow.com/questions/17259848/how-to-deal-with-hover-effect-on-touch-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!