简体   繁体   English

鼠标悬停时弹出窗口消失

[英]Popup disappear on mouse over

I am trying to display address on map on popup's as shown below in the image.我正在尝试在弹出窗口的 map 上显示地址,如下图所示。

Image of popup:弹出图像:

在此处输入图像描述

When I hover mouse on pin icon the popup appears but when I move to popup it disappear.当我将 hover 鼠标放在 pin 图标上时,会出现弹出窗口,但是当我移动到弹出窗口时,它会消失。

Javascript I am using: Javascript 我正在使用:

  <script>

        jQuery(function($) {
  var pop = $('.map-popup');
  pop.click(function(e) {
    e.stopPropagation();
  });

  $('a.marker').hover(function(e) {
    e.preventDefault();
    e.stopPropagation();
    $(this).next('.map-popup').toggleClass('open');
    $(this).parent().siblings().children('.map-popup').removeClass('open');
  });

  $(document).click(function() {
    pop.removeClass('open');
  });

  pop.each(function() {
    var w = $(window).outerWidth(),
        edge = Math.round( ($(this).offset().left) + ($(this).outerWidth()) );
    if( w < edge ) {
      $(this).addClass('edge');
    }
  });
});



    </script>

Code Pen link: codepen代码笔链接: codepen

Instead of代替

$('a.marker').hover(function(e) {

use利用

$('a.marker').mouseenter(function(e) {

hover handles both mouseenter and mouseleave events. hover处理 mouseenter 和 mouseleave 事件。 If you don't pass a handler for mouseleave, it will execute the function for mouseenter, so in your case,如果您没有为 mouseleave 传递处理程序,它将为 mouseenter 执行 function,所以在您的情况下,

$(this).next('.map-popup').toggleClass('open');

is executed again for mouseleave so the popup gets hidden.再次为mouseleave执行,因此弹出窗口被隐藏。 Read more here .在这里阅读更多。

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

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