2 different flyer popup styles
P粉702946921
2023-08-25 09:45:31
<p>Can Popups in Leaflet have 2 different styles? 2 different popups will be triggered on user interaction (in terms of style and content), one on mouseover and one on click. </p>
<p><strong>Issue: </strong>I am trying to override a CSS style in <code>.leaflet-popup-content-wrapper'</code> in a stylesheet that applies to a popup style. But it is not possible to switch CSS styles back and forth between the two CSS styles at runtime, possibly because the pop-up DOM element has not yet been loaded. </p>
<pre class="brush:php;toolbar:false;">marker.on('mouseover', function() {
marker.bindPopup('<b>Hello world</b>');
marker.openPopup();
})
marker.on('click', function() {
marker.bindPopup('<b>Click click</b>');
marker.openPopup();
// Failed attempt to switch style
$('.leaflet-popup-content-wrapper').addClass('new-style');
})</pre></p>
The
bindPopup
method can be passed an"options"
parameter, which can contain the"className"
attribute that will be added to the div. For popups: