见标题。它似乎可以很好地加载并很好地过渡到一张图片中,但在那之后拒绝工作。
当我使用 Chrome 检查并查看问题所在时,它告诉我它无法识别 slideSwitch 功能,即使我在本地测试它时一切正常。
无论如何,我希望stackoverflow的高手能够帮助我弱智的自己。
提前致谢。
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);
在这里阅读更多:window.setInterval from inside an object
我一遍又一遍地遇到同样的问题:)
关于jQuery 幻灯片在自定义 Wordpress 模板中的一张图片后停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938375/