【发布时间】:2014-01-10 23:19:00
【问题描述】:
我有一个 DIV,我想在鼠标悬停时显示它,在鼠标离开时隐藏它。
HTML:
<div id="test">TESTING</div>
CSS:
#test {
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 100px;
display: none;
background-color: #F00;
}
JS(假设我使用 jQuery):
$('#test').hover(function() {
$(this).fadeIn();
});
$('#test').mouseleave(function() {
$(this).fadeOut();
});
但它没有响应,也没有 JS 错误。我想我错过了一些愚蠢的事情。谁能给我点灯?
这里是JSFiddle
【问题讨论】:
-
因为元素被隐藏了......没有鼠标悬停在它上面
-
您希望如何在隐藏元素上处理鼠标事件?