如果单击标记,则忽略地图单击

时间:2014-04-03 13:26:55

标签: javascript jquery html events leaflet

我想要在标记上发生事件,然后停止事件地图。 我将mouseDown事件用于标记,将eventUp用于map。

如果我点击标记,然后打开div块,但如果我点击地图,则关闭div块。现在我点击了标记,它将一个div块和块立即关闭。

使用附加变量并不好,因为div块可能位于光标下,而地图上的mouseUp事件不会运行。

enter image description here

enter image description here

总结:如果我点击标记,地图事件就不会运行。

1 个答案:

答案 0 :(得分:0)

如果您不希望点击冒泡,可以使用.stopPropagation()

$('#marker').on('mousedown', function(e){
    // Do whatever you like
    // This is the 'normal' part of the code
}).on('mouseup', function(e){
    e.stopPropagation(); // stop the mouseup
});
  

描述:防止事件冒泡DOM树,   防止任何父处理程序被通知事件。

相关问题