Hoverintent 无法在悬停时隐藏 div

Hoverintent fails to hide div on hover

我用 id="navbar" 悬停在 div 上,它似乎什么也做不了。

我已经把这个添加到我的脑袋里了

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

代码:

ShowNavbar = function(){
  // show
}
HideNavbar = function(){
    // hide
}

var config = {    
  sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
  interval: 200, // number = milliseconds for onMouseOver polling interval    
  over: ShowNavbar(), // function = onMouseOver callback (REQUIRED)    
  timeout: 1500, // number = milliseconds delay before onMouseOut    
  out: HideNavbar() // function = onMouseOut callback (REQUIRED)
 };
$("html #navbar").hoverIntent( config );

我的旧代码有效

var timeout
const doc = document;
const navbar = doc.getElementById("navbar");
navbar.onmouseover = function(){
  navbar.style.top = '0';
  window.clearTimeout(timeout);
  timeout = setTimeout(function() {
    HideNavbar()
  }, 1500);
};

我不熟悉hoverIntent,所以这是一个普遍的观察。

对于 overout,您没有将 reference 传递给函数,而是在调用函数时传递函数的结果在你的对象中

试试这个。

var config = {    
  sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
  interval: 200, // number = milliseconds for onMouseOver polling interval    
  over: ShowNavbar, // function = onMouseOver callback (REQUIRED)    
  timeout: 1500, // number = milliseconds delay before onMouseOut    
  out: HideNavbar // function = onMouseOut callback (REQUIRED)
 };