0

在计时器之后,图像 div 变为空白,而不是切换到下一张图片。它应该循环图像1-4并无限重复

$('.carouselImageJavascriptActive').removeClass('carouselImageJavascriptActive');
$(this).addClass('carouselImageJavascriptActive');
var imgs=$(this).attr('.carouselImage')
var self = $(this);
var myImage = new Array();
var x=0;

myImage[0]='img/image1.jpg';
myImage[1]='img/image2.jpg';
myImage[2]='img/image3.jpg';
myImage[3]='img/image4.jpg';

setTimeout(function() {

    var img = document.getElementById('.carouselImageJavascriptActive');
    img.src = myImage[x];
    x++;

    if(x >= myImage.length){
        x = 0;
    } 
},2000);

HTML

<div id='challengeTwoImageJavascript' class='sectionChallengeCarouselImage'>
    <img id='imgj1' imgn='1' class='carouselImage carouselImageJavascriptActive' src='img/image1.jpg'/>
    <img id='imgj2' imgn='2' class='carouselImage' src='img/image2.jpg'/>
    <img id='imgj3' imgn='3' class='carouselImage' src='img/image3.jpg'/>
    <img id='imgj4' imgn='4'class='carouselImage' src='img/image4.jpg'/>
</div>
4

1 回答 1

0

这些图像的 id 都不是“.carouselImageJavascriptActive”。

于 2012-06-28T20:32:48.047 回答