JS Automatic Carousel Image Two cycle Method (original)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.