Javascript 传单Js自定义控件按钮添加(文本,悬停)
我跟着,这对我很有效。现在我想:Javascript 传单Js自定义控件按钮添加(文本,悬停),javascript,button,leaflet,Javascript,Button,Leaflet,我跟着,这对我很有效。现在我想: 将鼠标悬停在按钮上时显示一些文本(与缩放按钮类似) 当我将鼠标悬停在按钮上时,请更改按钮的颜色 能够在按钮内部写入文本而不是图像 代码如下: var customControl = L.Control.extend({ options: { position: 'topleft' }, onAdd: function (map) { var container = L
var customControl = L.Control.extend({
options: {
position: 'topleft'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-custom');
container.style.backgroundColor = 'white';
container.style.backgroundImage = "url(http://t1.gstatic.com/images?q=tbn:ANd9GcR6FCUMW5bPn8C4PbKak2BJQQsmC-K9-mbYBeFZm1ZM2w2GRy40Ew)";
container.style.backgroundSize = "30px 30px";
container.style.width = '30px';
container.style.height = '30px';
container.onclick = function(){
console.log('buttonClicked');
}
return container;
}
});
var map;
var readyState = function(e){
map = new L.Map('map').setView([48.935, 18.14], 14);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
map.addControl(new customControl());
}
window.addEventListener('DOMContentLoaded', readyState);
似乎你更需要一个按钮而不是一个div:
var container = L.DomUtil.create('input');
container.type="button";
container.title="No cat";
container.value = "42";
container.onmouseover = function(){
container.style.backgroundColor = 'pink';
}
container.onmouseout = function(){
container.style.backgroundColor = 'white';
}