2011-08-22 139 views
0

我想改變一個img-元件(PNG)當光標擊中元素的src-ATTRIB。 它在IE6以外的所有瀏覽器都能正常工作:(IE6:jQuery的pngfix +鼠標懸停事件

起初腳本通過jQuery PNGfix做了一個pngfix(),所以它用span標籤包裝了img元素並通過過濾器刪除了src內容into the span-tag。

我的想法是,爲了從運行時間跨度元素中取得樣式/ css/...而不是替換img-tag的src-attrib。這裏是一個我的代碼片段:

$(document).ready(function(){ 
$('img').bind 
({ 
    mouseover : function() 
    { 
     symbiontStatus = 1; 
     $('img').css('backgroundImage', 'img/img02.png'); 
//... 

在pngfix腳本我添加了一個類來跨度,這樣我就可以把它叫做:

$(document).ready(function(){ 
    $('.pngfix').bind 
    ({ 
     mouseover : function() 
     { 
alert('over!'); 
      symbiontStatus = 1; 
      $('.pngfix').css('backgroundImage', 'img/img02.png'); 
    //... 

我不知道拿到img02進入pngfix作爲背景。您?也許?

謝謝你, 馬里奧

回答

0

您可以設置圖像src屬性,然後再調用它pngfix。在此之前,你應該在img標籤後刪除該插件添加的span因爲pngfix將再次創建一個跨度。現在,我們將刪除您已綁定,我們將不得不livemouseover/mouseout事件span。試試這個

$(document).ready(function(){ 
    $('.pngfix').live('mouseover', function(){ 
      symbiontStatus = 1; 
      var $img = $(this).prev(); 
      $(this).remove() 

      $img.attr('src', 'img/img02.png').pngfix(); 
    //... 
    }); 
}); 
+0

http://jupiterjs.com/news/why-you-should-never-use-jquery-live(只是一篇不錯的文章。) –