我创建了一个简单的幻灯片,但它不起作用。 我已经使用了函数和setInterval但仍然看不到任何效果。 还有 css选择器
的任何错误
function slideshow() {
var $active = $('DIV#slider-wrap IMG.active');
var $next = $active.next();
$next.addClass('active');
$active.removeClass('active');
}
$(function(){
setInterval("slideshow",5000);
});

* {
margin:0;
padding:0;
}
#slider-wrap {
position:relative;
}
.slideshow .images {
width:100%;
max-width:960px;
height:350px;
overflow:hidden;
}
.slideshow .images img {
position:absolute;
width:100%;
max-width:960px;
height:auto;
}
.active {
z-index:99;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="slider-wrap">
<div class="slideshow">
<div class="images">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/1.jpg" alt="" class="active">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/2.jpg" alt="">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/3.jpg" alt="">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/4.jpg" alt="">
</div>
</div>
</div>
&#13;
帮我解决这个问题
答案 0 :(得分:4)
javascript setInterval接受函数的第一个参数而不是字符串。
function slideshow() {
var $active = $('div#slider-wrap img.active');
var $next = $active.next();
$next.addClass('active');
$active.removeClass('active');
}
$(function() {
setInterval(slideshow, 1000);
});
&#13;
* {
margin: 0;
padding: 0;
}
#slider-wrap {
position: relative;
}
.slideshow .images {
width: 100%;
max-width: 960px;
height: 350px;
overflow: hidden;
}
.slideshow .images img {
position: absolute;
width: 100%;
max-width: 960px;
height: auto;
}
.active {
z-index: 99;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="slider-wrap">
<div class="slideshow">
<div class="images">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/1.jpg" alt="" class="active">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/2.jpg" alt="">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/3.jpg" alt="">
<img src="http://tympanus.net/Tutorials/FullscreenSlitSlider/images/4.jpg" alt="">
</div>
</div>
</div>
&#13;