问题
I'm having trouble with a super simple slideshow I'm trying to make. I can't figure out why it won't work. The first picture shows up but it does not cycle through.
Here is the JSFiddle: http://jsfiddle.net/cydonknight/kyhxy/
and the JQuery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
setInterval("rotateImages()", 2000 );
});
function rotateImages(){
var $onCurrent= $('#imageSlider div.current') ;
var $onNext= $onCurrent.next().length ? $onCurrent.next();
: $('#imageSlider div:first');
if (!onNext.length )
onNext=$("#imageSlider div:first");
$onCurrent.addClass('previous');
$onNext.css({opacity: 0.0}).addClass('current').animate({opacity:1.0}, 2000, function() {
$onCurrent.removeClass(' previous');
});
}
</script>
Any help would be greatly appreciated!
回答1:
It is working now. I did lot of changes actually.
your updated fiddle
setInterval(rotateImages, 2000);
function rotateImages()
{
var $onCurrent= $('#imageSlider div.current') ;
var $onNext= $onCurrent.next().length ? $onCurrent.next() : $('#imageSlider div:first');
if (!$onNext.length )
$onNext=$("#imageSlider div:first");
$("#imageSlider div").removeClass("current").css("opacity", 0);
$onNext.addClass('current').animate({opacity:1.0}, 1000);
}
来源:https://stackoverflow.com/questions/13716970/jquery-trouble-with-simple-slideshow