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