我有以下問題。我正在研究一個簡單的jQuery工具提示,現在我正在處理一些對我來說很陌生的事情。每次我將鼠標懸停在元素上時,鼠標懸停和鼠標懸停的事件都會被觸發 - 所以工具提示會消失(但如果我保持交出狀態,它會在一秒內閃爍很多)。有我的代碼。jQuery懸停仍然觸發
var hint = $('<div id="hint-wrap"><div id="hintbox-top"><div id="hintbox-bottom"><div id="hintbox-topleft"><div id="hintbox-bottomleft"><div id="hint-innerwrap"><div id="hint"></div></div></div></div></div></div></div>'); // Funny I know :-D
hint.hide();
$('body').append(hint); // I append it
$('.hashint').hover(function(e){
// Set position to cursor's
hint.css('left', e.pageX);
hint.css('top', e.pageY - 60);
// animated append
hint.css('opacity', 0.2);
hint.show();
hint.animate({ 'opacity' : 1 }, 100);
// set text
$("#hint" , hint).html($('#' + $(this).attr('id') + '-hint').html());
},
function(){ // there is the problem
hint.hide();
});
和HTML:
<div id="usernamelabel-hint" class="hinttext">Lorem Ipsum is simply dummy text of the printing and type.Lorem. <a href="#">Sign up!</a></div> <!-- This is hint text (and code) -->
<p><label><span class="hashint" id="usernamelabel">Username</span><span class="asterisk">*</span></label> <!-- ... stuff --> </p>
請,沒有任何人知道爲什麼鼠標離開事件仍然引發和隱藏我的盒子?
非常感謝,的Ondrej
哦,你說得對!那就是問題所在。好的,thx的解決方案,但我想這將是更好的我的情況*以某種方式*使一些條件,如(如!ishover(el1)或!ishover(el2))el2.hide() – A123321 2010-01-10 16:52:12
很高興聽到.. .. :] – tillinberlin 2010-01-10 17:11:34