I'm trying to make a marker popup in Leaflet (1.3.1) that:
- Appears on mouseover ("hover")
- Disappears on mouseout
- Persists (stays open) on click
Here's what I have so far:
var marker1 = L.marker([51.505, -0.09]).addTo(mymap)
.bindPopup("<b>Hello world!</b><br />I am a popup.");
marker1.on('mouseover', function (e) {
this.openPopup();
});
marker1.on('mouseout', function (e) {
this.closePopup();
});
marker1.on('click', function (e) {
this.openPopup();
//disable mouseout behavior here?
});
Plunker: https://embed.plnkr.co/393lgE49Ndqsj7O6dg19/
Mouseover and mouseout work as expected. When I click on the marker, the popup briefly disappears before reappearing. When I mouseout, the marker disappears.
I'd like it if the popup didn't briefly disappear when I click on it, and instead just stayed open until the user clicks the close 'x' button or clicks somewhere else on the map.

closePopupOnClickoptions to work. :\ – MattSidor Feb 19 '18 at 04:26