我想要幻燈片在WordPress,但由於某種原因它不工作:變化圖像不工作(不能找到什麼導致它)
我的.js文件:
(function ($) {
function slideSwitch() {
var $active = $('#gallery1 IMG.active');
if ($active.length == 0) $active = $('#gallery1 IMG:last');
var $next = $active.next().length ? $active.next()
: $('#gallery1 IMG:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval("slideSwitch()", 5000);
});
});
CSS樣式:
#gallery1{
position: relative;
width:400px;
height:300px;
}
#gallery1 img{
position:absolute;
z-index:8;
}
#gallery1 img.active{
z-index:10;
}
#gallery1 img.last-active{
z-index:9;
}
的html代碼:
<div id="gallery1">
<img src="img1.jpg" class="active"/>
<img src="img2.jpg"/>
<img src="img3.jpg"/>
</div>
Chromes開發人員工具不顯示任何錯誤。雖然螢火蟲,顯示此錯誤: 錯誤斷點:
但我不明白第一個圖像有什麼問題,它加載正常。 有沒有人看到這個問題?
您可能想驗證您的第一行是否正在執行您認爲正在執行的操作。我不知道你在哪裏定義了這個腳本塊,但是如果它在頭部或者在你定義的圖像之前,那麼DOM可能不會被加載。嘗試使用$(document).ready速記版本,它是$(function(){[這是關於jQuery $(document).ready shorthand的前一個問題](http://stackoverflow.com/questions/6004129/document- ready-shorthand) – JustinMichaels 2012-08-02 12:03:19
你可以創建一個示例[jsFiddle](http://jsfiddle.net)來演示這個問題嗎? – 2012-08-02 12:08:48
這裏可能有一個範圍問題,你正在擴展JQuery對象的方式,我不是 – Sammaye 2012-08-02 12:08:53