Use the array to implement several pictures to cycle the display

Source: Internet
Author: User

2015-04-12 17:40:22

Using an array to implement a picture loop is to put the picture in an array and loop through the

Take four pictures as an example

<script>  //using an array object to achieve four images change the effect every 5 seconds var img=new array ();//Create Array object var index=0;//define array subscript img[0]=new Image (); img[ 0].src= '. /.. /.. /imgs/66.ico '; img[1]=new Image (); Img[1].src= '. /.. /.. /imgs/68.ico '; img[2]=new Image (); Img[2].src= '. /.. /.. /imgs/70.ico '; function Changepic () {document.images[0].src=img[index].src;index++;if (index==3) {index=0;}} SetInterval (' Changepic (); ', ');  </script> 

The diagram I'm using is an icon.

Image (): Pre-loaded Picture object

The second method:

<script>  var t=1;  function Changepic () {if (t==1) {document.images[0].src= ' 2.jpg '; t=2;} else if (t==2) {document.images[0].src= ' 3.jpg '; t=3;} else{document.images[0].src= ' 4.jpg '; t=1;}    }  Window.setinterval (' Changepic () ',;  </script> 

  

Use the array to implement several pictures to cycle the display

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.