2010-11-18 62 views
2

由於鼠標懸停和鼠標懸停,我在IE上遇到了一些下拉閃爍問題,所以我將代碼 更改爲懸停並生效,因爲數據是從ajax動態生成的。jquery live hover無法正常工作

但下面的代碼不工作,我也得到了最新的jQuery。是越來越沒有錯誤,但沒有工作

$('.cs-rec').live("hover", 
     function() {  
     $(this).find('.cs-title').css('text-decoration','underline'); 
     }, 
     function() { 
     $(this).find('.cs-title').css('text-decoration','none'); 
     } 
    ); 

回答

3

如果您不需要IE6的支持,一起去@帕特里克的解決方案完全執行

下面的代碼。

如果必須支持它:有沒有爲.live() 2方法重載你需要拆分成這樣:在jQuery的1.4

$('.cs-rec').live("mouseenter", function() {  
    $(this).find('.cs-title').css('text-decoration','underline'); 
}).live("mouseleave", function() { 
    $(this).find('.cs-title').css('text-decoration','none'); 
}); 

或者,(雖然它在文檔中的沒有) .3+可以拍一張地圖,像這樣:

$('.cs-rec').live({ 
    mouseenter: function() {  
    $(this).find('.cs-title').css('text-decoration','underline'); 
    }, 
    mouseleave: function() { 
    $(this).find('.cs-title').css('text-decoration','none'); 
    } 
}); 
+0

@nick,上面的代碼無法正常工作,而且其進行以下頁面上的菜單閃爍時,ABOV e代碼將在晚些時候開始運行,但是下降會像藝術風格一樣下降,如果有上述代碼,主題會在IE上閃爍http://locwww.art.com/products/p12838878-sa-i2055985/vincent%20van%20gogh-almond% 20branches%20in%20bloom,%20san%20remy,%20c.1890.htm?sorig = cat&sorigid = 0&dimvals = 23944&ui = 29ccdb60b8304c9c8de9008b6c546003 – kobe 2010-11-18 20:23:44

+0

@gov - 閃爍,因爲它映射到即使進入兒童時也會觸發的'mouseover'和'mouseout' ... CSS不是一個選項嗎?或者選擇直接綁定,以便實際使用'mouseenter'和'mouseleave'? – 2010-11-18 20:25:49

+0

@nick,我可以讓它內聯。 – kobe 2010-11-18 23:08:05

1

有沒有原因您不使用CSS? IE6將無法正常工作,但大多數人都會。

.cs-red .cs-title { 
    text-decoration: none; 
} 
.cs-red:hover .cs-title { 
    text-decoration: underline; 
} 

編輯:看你的網站,如果它是你在談論的導航區,你可以讓你有每個<li>內的<a>被擴展到整個寬度調整標記和<li>的高度。

這樣,可以支持IE6(將:hover置於<a>上)。

1

綁定到懸停是可能的,但棘手:

在jQuery的1.4.1懸停事件可以 指定(映射到的MouseEnter 和鼠標離開,這反過來,是 映射到鼠標懸停和鼠標)。

你必須使用一個方法,然後根據事件類型切換的行爲(從jQuery的文檔拍攝以及代碼示例):

$('.hoverme').live('hover', function(event) { 
    if (event.type == 'mouseenter') { 
     // do something on mouseover 
    } else { 
     // do something on mouseout 
    } 
}); 
0

這是真的...

$("#your_div_id").live('mouseover',function(){ 

    $(this).find(".child_div").css('background-color','#111111'); 

}).live('mouseout',function(){ 

    $(this).find(".child_div").css('background-color','#757575'); 
}); 
1
$('.edit_hover').live('hover', function(event) { 
    if (event.type == 'mouseenter') { 
    // first function here 
    } else { 
    // second function here 
    } 
});