我有一個水平導航菜單,我想顯示一個工具提示,當用戶的鼠標停留在按鈕上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