Javascript JQuery悬停时显示/隐藏面板

Javascript JQuery悬停时显示/隐藏面板,javascript,jquery,toggle,Javascript,Jquery,Toggle,可能重复: 我有一个简单的html页面: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script&

可能重复:

我有一个简单的html页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>

  <script>
      $(document).ready(function() {

          $("div").hide();

          $("button").hover(function() {
              $("div").slideDown("slow");
          });

          setTimeout(hidepanel, 4000);

          function hidepanel() {
              if ($('div').is(':hover') === false) {
                  $('div').slideUp(); 
              }
          }

          $('div').mouseleave(function() { setTimeout(hidepanel, 4000); });
          $('button').mouseleave(function() { setTimeout(hidepanel, 4000); });
      });
  </script>

  <style>
  div { width:400px; }
  </style>
</head>
<body>
  <button>Toggle</button>
  <div style="border: 1px solid">

    This is the paragraph to end all paragraphs.  You
    should feel <em>lucky</em> to have seen such a paragraph in
    your life.  Congratulations!
  </div>
</body>
</html>
我需要:

当鼠标光标位于按钮或面板div上时,显示面板div 当鼠标不在按钮或面板上方4秒时隐藏面板 当我在面板或按钮外的任何位置单击页面时,立即隐藏面板。 我应该如何更改我的代码

非常感谢

有趣的部分是在单击面板/按钮外部时隐藏面板

$(document).click(function (e) {    
    if (e.target.id !== "btn" && e.target.id !== 'panel' && $(e.target).parents('#panel').length === 0)
    {
       hidepanel(); 
    }
});

显然,你会希望选择器比DIV和button更具体,但你明白了。

为什么你不能一次问清楚:为什么要重新发明轮子?为什么不使用现有的jQuery插件,比如clueTip?Kalle H.Väravas?很抱歉,不同的问题和不同的解决方案