我有一个水平导航菜单,我想显示一个工具提示,当用户的鼠标停留在按钮上1秒。换句话说,我希望在那里出现提示时会有延迟。当用户移开鼠标时,工具提示应立即消失。 Stumbleupon的工具栏是我希望如何运作的例子。jquery悬停setTimeout
的javascript:
$("a.btn").hover(
function() {
var tip = $(this).parent().children(".tip-wrapper");
setTimeout(function{
tip.show();
}, 1000)
},
function {
var tip = $(this).parent().children(".tip-wrapper");
tip.hide();
}
);
HTML:
<th title="">
<a href="#" class="btn">
<span class="person">Firstname Lastname</span>
</a>
<div class="tip-wrapper">
<div class="tip-border">
<div class="tip">
tool tips go here
</div>
</div>
</div>
</th>
我已经看了很多教程,不能找出为什么我的不行。
或者在使用stop(避免超时变量)时匹配原始意图,请使用delay(1000).fadeIn(0):http://jsfiddle.net/Lobstrosity/wscUw/ – Lobstrosity