change img src in each 5 sec with three photo with Jquery -


images

  1. sf.jpg
  2. sf2.jpg
  3. sf3.jpg

change above img src in each 5 sec in first 5 sec image should sf.jpg in second 5 sec image should sf2.jpg in third 5 sec image should sf3.jpg

and should work repeatdly forever

check below code snippet.

i have altered alt attribute after 2 secs. in code replace alt src.

$(window).on('load', function() {    let src = ['image_1.jpg', 'image_2.jpg', 'image_3.jpg', 'image_4.jpg'];    let = 1;    setinterval(function() {      $('img').prop('alt', src[i]);      if (i !== src.length)        i++;      else        = 0;    }, 2000);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <img src='image_1.jpg' alt='image_1.jpg' width='200' height='200' />

hope, works you. :) :)


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -