2011-11-12 91 views
1

我有一個jquery圖像幻燈片插件問題,我正在處理圖像向左滾動創建幻燈片的位置。 IE和FireFox工作正常,但Safari/Chrome(WebKit)不會工作。動畫左側在webkit(Chrome/Safari)中無法正常工作

這個問題的電話

$(".nav li").live("click", function() { 
    if (lastSelected != null) $(lastSelected).removeClass("selected"); 
    $(this).addClass("selected"); 
    place = parseInt($(this).text()); 
    if (place > last) { 
     offset = parseInt(place - last); 
     direction = "-="; 
    } 
    else { 
     offset = parseInt(last - place); 
     direction = "+="; 
    } 

//這是它僅適用於IE和FF

$(".slideshow img").each(function() { 
     $(this).animate({ 
      left: direction + (offset * imageWidth) + "px" 
     }); 
    }); 

//我是不是做錯了什麼嗯?

reset = true; 
    last = place; 
    lastSelected = $(this); 
}).css("cursor", "pointer"); 
+0

你可以給我們一個使用像http://jsfiddle.net/在線工具的演示,所以我們可以更容易地測試它嗎? – fflorent

回答

0

所以我一直在做一些調試的發現,彌補*圖片寬度在Chrome中保持爲0!

發現

解決方案:

  1. Get the real width and height of an image with JavaScript? (in Safari/Chrome)
  2. http://name1price.com/how-to-get-customers-with-singapore-web-design-basic/jquery-tutorials/149-jquery-get-image-height-or-width-returns-0-problem-.html

這兩個來源幫助修復 「的jQuery得到圖像高度或寬度,則返回0的問題」,這是最初的問題。我現在正在使用上面第一個解決方案中找到的修復程序,並且工作正常。

1

這是什麼lastSelected

你確定

$(lastSelected).removeClass("selected"); 

工作???

因爲

lastSelected is an `object` not an attribute 

試試這個(假設你有一個id屬性)

lastSelected = $(this).attr('id'); 

if (lastSelected != null) $('#'+lastSelected).removeClass("selected"); 
+0

感謝Kanish, 正如您在代碼中看到的,lastSelect被更改爲$(this),它是當前對象,下一次運行時它是最後一個對象。這工作正常。 所以我一直在做一些調試,發現(偏移量* imageWidth)在WebKit瀏覽器(Safari/Chrome)中保持爲0,我已經修改了一些有問題的代碼,現在住在這裏:http:// garruu .dyndns.org 我不明白爲什麼這個值在WebKit瀏覽器中不起作用;所以,我要去看看,手指交叉。 – JeffreyJ

+0

因此,一些更多的調試發現imageWidth沒有獲得WebKit Browers中的圖像寬度。我還發現WebKit修復將把圖像寬度放在標記中。我更喜歡動態的解決方案,並不會關閉這個線程,直到我得到更好的解決方案。 – JeffreyJ