change img src in each 5 sec with three photo with Jquery -
images
- sf.jpg
- sf2.jpg
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
Post a Comment