Samuel Toh

Samuel Toh

  • NA
  • 106
  • 14.1k

Change background automatically

Nov 9 2021 6:49 AM

<html>
<head>
  <title>change picture</title>
  <script type = "text/javascript">
      function displayNextImage() {
          x = (x === images.length - 1) ? 0 : x + 1;
          document.getElementById("img").src = images[x];
      }
      function changeImage() {
          setInterval(displayNextImage, 5000);
      }

      var images = [], x = -1;
      images[0] = "Apple_History1.jpg";
      images[1] = "Apple_History2.jpg";
      images[2] = "Apple_History3.jpg";
  </script>
  </head>
  <body>
   <img id="img" src="../Images/Apple_History1.jpg"/>
  </body>
  </html>

 

I'm not sure why It doesn't work. How do I change my Background every 5 seconds with HTML? I am using asp.net, visual studio


Answers (2)