【发布时间】:2015-04-13 12:10:37
【问题描述】:
我已经到处搜索了,但找不到这个确切问题的解决方案。
在桌面浏览器上,当用户将鼠标悬停在图像上时,会出现一个 div,如果需要,他们可以单击 div 内的链接。但是,在移动设备上,悬停是由点击触发的。如果用户在正确的位置单击,即使 div 尚不可见,他们也可能不小心单击锚点并离开页面。 (换句话说,在点击链接的同时,div 从display:none 变为display:block。)
我想防止在移动浏览器上发生意外点击,但是我仍然希望链接在 div 可见后仍然可用。
我的代码:
<style>
.staffpic {
position: relative;
width: 33.33333%;
height: auto;
}
.staffpic:hover .popup {
display: block;
}
.staffpic img {
display: block;
width: 110px;
height: 110px;
margin: 0 auto;
}
.popup {
display:none;
position: absolute;
bottom: 0;
left: -5px;
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 15px;
background-color: rgba(255, 153, 0, 0.9);
color: #fff;
text-transform: uppercase;
}
</style>
<div class="staffpic">
<img src="/wp-content/uploads/image.jpg" />
<div class="popup">
John Smith, Director<br/>
CityName | <a href="mailto:johnsmith@example.com">Email John</a>
</div>
</div>
有什么想法吗?欢迎使用 HTML、CSS、JS 和 jQuery 解决方案! (也许比我能想到的使用 pointer-events:none 和一些 jQuery 更聪明的东西?)
【问题讨论】:
标签: javascript jquery html css hover