【发布时间】:2021-01-27 13:03:02
【问题描述】:
当我想在传单地图上添加交互性时遇到问题。
我的地图上有一个按钮
<button id="az">Availability Zones</button>
我想要的是当我点击它时,它会在我的地图上显示一个正方形的信息 所以我创建了一个正方形
<div class="square" id='square'> </div>
CSS = .square{
z-index: 4000;
width: 100%;
height: 0;
padding-top: 100%;
background-color: #ccc;
position: absolute;
display: none;
}
还有一个具有相同属性但带有显示的 css 类方块:块
.squareclick{
z-index: 4000;
width: 30%;
weight: 30%;
padding: 0 25 30;
margin-left: 400px;
margin-bottom: 200px;
height: 0;
padding-top: 100%;
background-color: #ccc;
position: relative;
display: block;
}
现在,为了在按钮上打开这个方块,我添加了一些交互性
var button = document.getElementById('az')
L.DomEvent.on(button,'click',function(e){
console.log('Button clicked')
});
L.DomEvent.on(button,'click',function(){
document.getElementById('square').setAttribute("class", "squareclick");
});
问题是那个按钮可以用来打开正方形,但不能用来关闭(我知道这是正常的) 我试过那个东西,但它似乎不起作用
L.DomEvent.on(button,'click',function myFunction() {
var x = document.getElementById("square");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
我不知道如何在同一个按钮上添加第二个交互性:(
如果有人可以帮忙! 非常感谢
【问题讨论】:
标签: javascript html css leaflet maps