With 5 Div, the layout from left to right 5 pictures, from left to right 5 div. (The background is relative,5 Div is relative to the background absolute positioning)
Shown below:
Method One: (assign a div directly to the other, turn the carousel once to For Loop 5)
1 functionAutoPlay () {2 varX,y,baoliu;3Baoliu=document.getelementbyid ("Img5"). Style.backgroundimage;4 for(i=5;i>0;i--){5Y=document.getelementbyid ("img" +i);6 if(i==1){7x=Baoliu;8Y.style.backgroundimage=x;9 }Ten Else{ OneX=document.getelementbyid ("img" + (i-1)); AY.style.backgroundimage=X.style.backgroundimage; - } - } the}
Method Two: (22 exchange with each other, carousel for A For Loop 4)
1 functionAutoPlay () {2 varX,y,baoliu;3 for(i=5;i>1;i--){4X=document.getelementbyid ("img" + (i-1));5Y=document.getelementbyid ("img" +i);6baoliu=Y.style.backgroundimage;7Y.style.backgroundimage=X.style.backgroundimage;8X.style.backgroundimage=Baoliu;9 }Ten}
The result of a carousel:
In the end, we need to analyze the merits of these two methods.
JS Automatic Carousel Image Two cycle Method (original)