简体   繁体   English

如何在带有可点击内容的悬停事件上打开弹出窗口

[英]how to open a popup on hover event with clickable contant

i am currently working with leaflet. 我目前正在使用传单。

and i am trying to create a popup with with clickable content. 我正在尝试创建带有可点击内容的弹出窗口。

now i found how i can bind popups on click event with content: 现在,我发现了如何将点击事件中的弹出窗口与内容绑定在一起:

marker.on('click', function(e){
     marker.bindPopup("<div />").openPopup();
}

and i found out how to create the popup on hover: 我发现了如何在悬停时创建弹出窗口:

marker.on('mouseover', function(e){
    e.target.bindPopup("<div />").openPopup();

    }});        

marker.on('mouseout', function(e){  
    e.target.closePopup();

}});

now what i cant seem to do is make the popup stay open in order for the user to click on links inside the popup. 现在,我似乎无法做的是使弹出窗口保持打开状态,以便用户单击弹出窗口内的链接。 i would appreciate any help. 我将不胜感激任何帮助。

one approach is this http://jsfiddle.net/cxZRM/98/ basically it's adding a timer to your setup and you only close the popup after an arbitrarily long time has passed so as to give the user some time to interact on your div. 一种方法是http://jsfiddle.net/cxZRM/98/基本上是在您的设置中添加一个计时器,并且只有在经过任意长时间后才关闭弹出窗口,以便给用户一些时间在div上进行交互。

marker.on('mouseover', function(e){
    e.target.bindPopup("dsdsdsdsd").openPopup();
    start = new Date().getTime();
  });        

marker.on('mouseout', function(e){  
    var end = new Date().getTime();
    var time = end - start;
    console.log('Execution time: ' + time);
    if(time > 700){
    e.target.closePopup();
    }
});

a better approach would be to use http://jsfiddle.net/AMsK9/ to determine your mouse position and keep the popup open while the mouse is still within an area around the popup. 更好的方法是使用http://jsfiddle.net/AMsK9/确定鼠标的位置,并在鼠标仍位于弹出窗口周围的区域内时保持弹出窗口打开。

I had the same issue, I wanted a different pop up for mouseover and another one for click, and the problem was that when I hovered out the click pop up closed, so what I did was adding a flag: 我遇到了同样的问题,我想要一个不同的弹出窗口用于鼠标悬停,另一个希望用于单击鼠标悬停,问题是当我将鼠标悬停在弹出窗口上方时,我所做的就是添加一个标志:

var modal = true;    
function onEachFeature(feature, Polygon) 
    {
        if (feature.properties && feature.properties.popupContent && feature.properties.modal) 
        { 
            Polygon.on('mouseover', function (e) {
              Polygon.bindPopup(feature.properties.popupContent);
              this.openPopup();
              modal = false;
            });
            Polygon.on('mouseout', function (e) {

                if(!modal)
                this.closePopup();
            });
            Polygon.on('click', function (e) {
                modal = true;
                Polygon.bindPopup(feature.properties.modal).openPopup();
            });

        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM