jQuery:检测mouseover隐藏的元素

时间:2017-01-24 20:03:41

标签: jquery html

我正在寻找一个有趣的巨魔网站(click here to see it),我希望只有当鼠标悬停在按钮上时才会显示该按钮。但是,jQuery的“鼠标悬停”操作不会检测您的光标是否在隐藏元素上。有什么方法可以用不同的动作完成这个,或者我必须用HTML做按钮吗?

$("document").ready(function(){
    $("#button").mouseenter(function(){
        $("#button").hide();
    });
    $("#button").mouseleave(function(){
        $("#button").show();
    });
});

2 个答案:

答案 0 :(得分:1)



#button:hover {
  opacity: 0;
  cursor: text;
}

<p>
  Some text<br/>
  
  <button id="button" onclick="return false;">And a jumpy button</button><br/>
  
  Followed by more text
</p>
  
  
&#13;
&#13;
&#13;

答案 1 :(得分:0)

.hide().show()方法设置了CSS display:none设置。这使得元素不可移动(如果存在这样的单词:D),那么,您需要设置元素的可见性:

$("document").ready(function(){
    $("#button").mouseenter(function(){
        $("#button").css('visibility', 'hidden');
    });
    $("#button").mouseleave(function(){
        $("#button").css('visibility', 'visible');
    });
});
相关问题