_javascript technique of picture Carousel based on JavaScript array

Source: Internet
Author: User
Tags setinterval javascript array

There are many ways to do a picture carousel, which introduces a simple: JS array implementation.

First store the picture path in the array, and then call the SetInterval function to turn the picture in turn

 <script type= "Text/javascript" > 
  var curindex = 0; 
  var timeinterval = 1000; 
  var arr = new Array (); 
  Arr[0] = "1.png"; 
  ARR[1] = "2.png"; 
  ARR[2] = "3.png"; 
  ARR[3] = "4.png"; 
  ARR[4] = "5.png"; 
  SetInterval (changeimg,timeinterval); 
  function changeimg () { 
    var obj = document.getElementById ("Imge"); 
    if (Curindex = = arr.length-1) { 
     curindex = 0; 
    } else { 
     curindex = 1; 
    } 
    OBJ.SRC = Arr[curindex]; 
  } 
 </script>

The complete example is as follows

 <! DOCTYPE html>  
 

The above is the entire content of this article, I hope to help you learn.

Related Article

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.