在 MouseOver 事件上调用 Leaflet Mouseout

Leaflet Mouseout called on MouseOver event(在 MouseOver 事件上调用 Leaflet Mouseout)
本文介绍了在 MouseOver 事件上调用 Leaflet Mouseout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一张传单地图,我在其中动态添加标记.

I have a leaflet map where I'm dynamically adding markers.

当我将鼠标悬停在标记上时以及单击标记时,我想调用它的弹出窗口.

I want to call the popup for a marker when I hover over it in addition to when I click the marker.

我的代码是:

function makeMarker(){
   var Marker = L.marker...
   Marker.on('mouseover', function(){Marker.bindPopup('HI').openPopup();});

   Marker.on('mouseout', function(){Marker.closePopup();});
}

如果我注释掉 mouseout 行,则会出现弹出窗口,但我必须单击 elswhere 将其关闭.问题是当我将鼠标移出时,光标在光标悬停在标记上时有点闪烁,没有任何显示.我认为弹出窗口正在打开但关闭速度非常快,这就是光标闪烁的原因,但我不知道如何解决这个问题

If I comment out the mouseout line, then the popup appears but then I have to click elswhere to close it. The problem is when I put in the mouseout, at that point, the cursor kinda flickers when it hovers over the marker and nothing shows. I think that the popup is openning but then closing really fast which is why the cursor flickers but I don't know how to fix this

推荐答案

弹出窗口实际上是在光标下方加载并从 Marker 中窃取"鼠标,触发 Marker.mouseout() 事件,从而导致弹出窗口关闭并重新触发 Marker.mouseover() 事件...循环继续,这就是您看到闪烁"的原因.

The popup is actually loading underneath the cursor and 'stealing' the mouse from the Marker, triggering the Marker.mouseout() event, which causes the popup to close and re-triggers the Marker.mouseover() event... and the cycle continues which is why you see the 'flicker'.

我已经看到这种情况取决于缩放级别(通常在缩小时).

I have seen this happen depending on the zoom level (usually when zoomed right out).

尝试在弹出选项中添加偏移量以使其不碍事:

Try adding an offset into your popup options to get it out of the way:

function makeMarker(){
   var Marker = L.marker...
   Marker.on('mouseover', function(){Marker.bindPopup('HI', {'offset': L.point(0,-50)}).openPopup();});

   Marker.on('mouseout', function(){Marker.closePopup();});
}

这篇关于在 MouseOver 事件上调用 Leaflet Mouseout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)