我有一个脚本,显示隐藏的文字,当你将鼠标悬停在一个div。但我希望它延迟2秒,如果用户在2秒之前移开鼠标,我不想显示任何内容。jQuery的。对(“的mouseenter”) - 等待2秒,然后做动作
我该怎么做?
我有什么:http://jsfiddle.net/ZhrJT/
-
HTML:
<body>
<div>hover this</div>
<p class="hidden">unhidden!!</p>
</body>
JS:
$("body").on("mouseenter", "div", function(){
$("p").removeClass("hidden");
}).on("mouseleave", "div", function(){
$("p").addClass("hidden");
});
CSS:
div {
background-color:red;
height:100px;
}
p.hidden {
display:none;
}
p {
background-color:yellow;
height:100px;
}
http://cherne.net/brian/resources/jquery.hoverIntent.html可能是你在找什么 – PeeHaa