1

我有一个元素会在我单击按钮后出现。我现在想要的是当我的鼠标指针离开元素时隐藏元素。这怎么可能?谢谢

JS脚本:

          $(document).ready(function() {

          $('.hide').hide();



          $('.button').click(function() {
            $(this).closest('div').find('.hide').toggle(400);
            return false;           
          });

HTML 代码:

<a class="button" >More</a>

<div class="hide" ><img src="images/icon.png" /></div>
//I want this div hide element to hide after my mouse pointer leave this div area

非常感谢 :D

4

2 回答 2

8
$("div.hide").mouseleave(function(){
    $(".hide").hide();
});

为了再次显示 div 内容,您可以使用 mouseenter() ,例如:

$("div.hide").mouseenter(function(){
    $(".hide").show();
});

或者您也可以这样做:(供切换使用)

$("div.hide").mouseleave(function(){
    $(".hide").hide();
}).mouseenter(function(){
    $(".hide").show();
});
于 2013-05-09T08:07:10.390 回答
0

您是否尝试过使用mouseout事件?

http://api.jquery.com/mouseout/

于 2013-05-09T08:06:41.083 回答