请参阅标题。它似乎加载得很好,很好地过渡到一张图片中,但之后就拒绝工作了。
当我使用Chrome查看问题所在时,它告诉我它无法识别slideSwitch功能,尽管我在本地测试时一切正常。
不管怎样,我希望斯塔克弗洛的大师们能够帮助我虚弱的自己。
提前谢谢。
jQuery代码:
$(function slideSwitch() {
var $active = $('#slideshow img.active');
if ($active.length == 0) $active = $('#slideshow img:last');
var $next = $active.next().length ? $active.next() : $('#slideshow img:first');
$active.addClass('last-active');
$next.css({
opacity: 0.0
}).addClass('active').animate({
opacity: 1.0
}, 2000, function () {
$active.removeClass('active last-active');
});
});
$(function () {
setInterval("slideSwitch()", 5000);
});
这是它附带的CSS:
#slideshow {
height:327px;
border:thick #000;
list-style:none;
margin:0px auto;
width:600px;
overflow: hidden;
position:relative;
}
#slideshow img {
border: solid #000000 10px;
display:block;
position:absolute;
z-index: 8;
}
#slideshow img.active {
z-index:10;
}
#slideshow img.last-active {
z-index:9;
}
因为setinterval是一个eval。
这样做:
window.setInterval(function() {
slideSwitch();
}, 5000);
请参阅:http://jsfiddle.net/cxPU6/
点击此处阅读更多:window.setInterval来自对象内部
我一次又一次地遇到同样的问题:)
尝试:
setInterval( function(){
slideSwitch();
}, 5000 );