我正在尝试制作一个包含相关信息的互动地图。当您点击一个点时,它会调整大小并显示一些联系人。这是因为元素获得:active
和:focus
伪类。
有没有办法在第二次单击时从元素中删除伪类?实际上,是否可以在再次单击时使元素关闭?
.distribution-map {
position: relative;
width: 100%;
padding: 20px;
box-sizing: border-box;
margin: 0 auto;
}
.distribution-map .map-point {
cursor: pointer;
outline: none;
top: 20px;
position: absolute;
width: 40px;
height: 40px;
border-radius: 20px;
}
.distribution-map .map-point:active,
.distribution-map .map-point:focus {
margin: 0;
padding: 0;
filter: opacity: 1;
width: 300px;
height: 220px;
color: #e5e5e5;
z-index: 1;
-webkit-transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
}
<div class="distribution-map">
<button class="map-point">
</button>
</div>
答案 0 :(得分:4)
pointer-events: none;
通过将pointer-events: none;
添加到焦点元素,您可以停止在元素上进行鼠标交互,从而有效地在下一次点击时不会聚焦。
需要进行以下修改:
pointer-events: none;
添加到.distribution-map .map-point:active, .distribution-map .map-point:focus
.distribution-map {
position: relative;
width: 100%;
padding: 20px;
box-sizing: border-box;
margin: 0 auto;
}
.distribution-map .map-point {
cursor: pointer;
outline: none;
top: 20px;
position: absolute;
width: 40px;
height: 40px;
border-radius: 20px;
}
.distribution-map .map-point:active,
.distribution-map .map-point:focus {
margin: 0;
padding: 0;
filter: opacity: 1;
width: 300px;
height: 220px;
color: #e5e5e5;
z-index: 1;
-webkit-transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
pointer-events: none;
}
<div class="distribution-map">
<button class="map-point">
</button>
</div>