samedi 17 août 2019

How to set image interval in Jquery without repeating?

How can I set the interval timing for it to loop the images and in every 1 second, an image is randomly selected from the three remaining images and replaces the current image.

  <h2>Click an image for a link.</h2>
  <div id="ads">
  </div>
  <script>
    var image = new Array ();
    image[0] = "<img src='images/gallery1.jpg'></a>";
    image[1] = "<img src='images/gallery2.jpg'></a>"

    var link = new Array ();
        link[0] = "<a href='https://www.gooogle.com' target='_blank'>";
        link[1] = "<a href='https://www.twitter.com' target='_blank'>";
$(document).ready(function randImg() {
    var size = image.length;
    var x = Math.floor(size*Math.random());
    $('#ads').append(link[x]+image[x]);
  });
  </script>

I expect every 1 second, changes an image of a webpage based on four existing images. For this purpose, in every 1 second, an image is randomly selected from the three remaining images and replaces the current image.




Aucun commentaire:

Enregistrer un commentaire