Image Slide Show

Simple image slide show

by Himanshu Dhiraj Mishra

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<h2>Image Slide Show - Image Changes Every 3 Seconds</h2><br />
<img id="imageSlide" class="imgdiv" src="http://lorempixel.com/output/city-q-c-370-340-6.jpg"/>

JavaScript

$(function() { 
var imgs = [
'http://lorempixel.com/output/nature-q-c-370-340-6.jpg',
'http://lorempixel.com/output/nature-q-c-370-340-2.jpg',
'http://lorempixel.com/output/city-q-c-370-340-4.jpg',
'http://lorempixel.com/output/city-q-c-370-340-6.jpg'];
var cnt = imgs.length;
var $imageSlide = $('img[id$=imageSlide]');
// set the image control to the last image
$imageSlide.attr('src', imgs[cnt-1]);
setInterval(Slider, 3000);
function Slider() {
$imageSlide.fadeOut("slow", function() {
$(this).attr('src', imgs[(imgs.length++) % cnt])
.fadeIn("slow");
});
}
});