代码之家  ›  专栏  ›  技术社区  ›  Shyju

当我将光标移到元素上而不离开元素时调用onmouseout JavaScript事件

  •  1
  • Shyju  · 技术社区  · 14 年前

    onmouseover 我将调用一个JavaScript函数来显示工具提示,并在 onmouseout

    如果我在图像中移动鼠标,它会调用 事件(即使我没有脱离图像)。我怎样才能阻止这一切?我想要 当光标离开图像时调用。有什么想法吗?

    我这样称呼它:

     <img src="images/customer.png" onmouseout="HideCustomerInfo()" onmouseover="ShowCustomerInfo(485)" />
    

    在我的JavaScript中:

     function ShowCustomerInfo(id) {
    
    
     var currentCustomer = $("#hdnCustomerId").val();   
     if (currentCustomer != id) { // to stop making an ajax call everytime when the mouse move on the same image
         
         $.get('../Lib/handlers/userhandler.aspx?mode=custinfo&cid=' + id, function (data) {
             strHtml = data;
         });
    
         tooltip.show(strHtml);   // method in another jquery pluggin
         $("#hdnCustomerId").val(id);
     }
    }
    
    function HideCustomerInfo() {
    
     tooltip.hide();    // method in another jquery pluggin
     $("#hdnCustomerId").val(0); //setting in a hidden variable in the page
    
     }
    
    3 回复  |  直到 4 年前
        1
  •  2
  •   Dmitry Reutov    4 年前

    我假设你正在鼠标滑过你的工具提示?工具提示的标记在图像的范围之外?

    因此,将鼠标悬停在工具提示上,从技术上讲,就是在离开图像。我也经历过类似的事情。

    为了解决这个问题,试着用 div 在图像周围,并将鼠标事件放在 部门 有你的工具提示,所以即使当你把鼠标移到工具提示上,你仍然在 部门

    那可能有用。

        2
  •  1
  •   Levente Farkas    11 年前

    如果你用来悬停的图像是透明的(右边是png),那么当你把鼠标移到图像的透明部分时,你会得到一个onmouseout事件。是啊,糟透了。我也有同样的问题,但还没有一个完美的解决方案。

        3
  •  0
  •   bugventure    14 年前

    你确定吗? HideCustomerInfo() onmouseout 图像的事件处理程序?还有,你在什么浏览器里看到的?你在一个特定的浏览器中有这种行为吗?

        4
  •  0
  •   Igor de Paula    4 年前

    另一个简单的方法是设置 pointer-events: none 在工具提示上

    推荐文章