簡體   English   中英

鼠標懸停時彈出窗口消失

[英]Popup disappear on mouse over

我正在嘗試在彈出窗口的 map 上顯示地址,如下圖所示。

彈出圖像:

在此處輸入圖像描述

當我將 hover 鼠標放在 pin 圖標上時,會出現彈出窗口,但是當我移動到彈出窗口時,它會消失。

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>

代碼筆鏈接: codepen

代替

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

利用

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

hover處理 mouseenter 和 mouseleave 事件。 如果您沒有為 mouseleave 傳遞處理程序,它將為 mouseenter 執行 function,所以在您的情況下,

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

再次為mouseleave執行,因此彈出窗口被隱藏。 在這里閱讀更多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM