在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)