Jump to content

[SOLVED] Change image after some time


Allan-

Recommended Posts

I want to change image src after some time to another (after 3 secs in example) and if there arent more images then turn into the first one again. In example I have 3 different image sources (gfx/img1.jpg, gfx/img2.jpg, gfx/img3.jpg).

 

This is part of my code but something is wrong there. Can someone help?

 

   <script type="text/javascript">
      var i = 0;
      var image = document.getElementById('changeimage');
      function changeImage() {
         if (i == 0) {
            image.src = 'gfx/img1.jpg';
            i = 1;
         } else if (i == 1) {
            image.src = 'gfx/img2.jpg';
            i = 2;
         } else {
            image.src = 'gfx/img3.jpg';
            i = 0;
         }
         setTimeout('changeImage()', 3000);
      }

   </script>

</head>

<body onload="changeImage();">
   <img id="changeimage" src="gfx/img1.jpg" />

Link to comment
https://forums.phpfreaks.com/topic/138159-solved-change-image-after-some-time/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.