gpt4 book ai didi

javascript - 使传单上的叠加 div 无法点击

转载 作者:太空狗 更新时间:2023-10-29 15:10:33 26 4
gpt4 key购买 nike

我如何在传单 map 上制作覆盖 div 而不是点击?我设置我在覆盖的 div 上尝试了 pointer-events: noneauto,但这没有帮助。将 pointer-events 设置为 none 会导致 radiobutton 不再可点击...

// We’ll add a tile layer to add to our map, in this case it’s a OSM tile layer.
// Creating a tile layer usually involves setting the URL template for the tile images
var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, {
maxZoom: 18,
attribution: osmAttrib
});

// initialize the map on the "map" div with a given center and zoom
var map = L.map('map').setView([19.04469, 72.9258], 12).addLayer(osm);

// Script for adding marker on map click
function onMapClick(e) {

var marker = L.marker(e.latlng, {
draggable: true,
title: "Resource location",
alt: "Resource Location",
riseOnHover: true
}).addTo(map)
.bindPopup(e.latlng.toString()).openPopup();

// Update marker on changing it's position
marker.on("dragend", function(ev) {

var chagedPos = ev.target.getLatLng();
this.bindPopup(chagedPos.toString()).openPopup();

});
}

map.on('click', onMapClick);
#map {
height: 500px;
width: 80%;
z-index: 1;
position: relative;
}

.overlay {
height: 500px;
width: 100px;
position: absolute;
right: 0px;
z-index: 2;
background-color: rgba(255, 50, 50, 0.5);
pointer-events: auto;
}
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<link href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" rel="stylesheet" />

<div id="map">
<div class = "overlay">
<input type="radio" class = "someButton">Foo Bar
</div>
</div>

最佳答案

另一种解决方案是使用 leaflet 自己提供的方法。

var div = L.DomUtil.get('overlay'); // this must be an ID, not class!
L.DomEvent.on(div, 'mousewheel', L.DomEvent.stopPropagation);
L.DomEvent.on(div, 'click', L.DomEvent.stopPropagation);

关于javascript - 使传单上的叠加 div 无法点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39764833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com