JQUERYIntermediate

jQuery Image Slideshow

PB Pb28 Master Team July 12th, 2022 Intermediate

📦 Get the complete source code for this tutorial

In this tutorial, we are going to display image using jQuery auto slideshow. In the previous tutorial, we have seen an example for DIV auto load and refresh using jQuery.

We are having a list of images to be displayed in a slideshow. jQuery fadeIn()/fadeOut() functions are used to show image slides one by one.

View Demo

HTML Image List

This code contains a list of images in a div container.

image-slide

html
<div id="image-slide">

	<img class="slide" src="slides/beach1.jpg"/>

	<img class="slide" src="slides/beach2.jpg"/>

	<img class="slide" src="slides/beach3.jpg"/>

	<img class="slide" src="slides/beach4.jpg"/>

	<img class="slide" src="slides/beach5.jpg"/>

</div>

jQuery Slideshow

This function show and hide the list of images in a periodic interval by using jQuery fadeIn() fadeOut().

javascript
$(document).ready(function() {

	$(".slide:first").show();

	setInterval(function(){ Next($('.slide:visible'))}, 2400);



});

function Next(slide) {

	slide.fadeOut();

	if(typeof slide.next().attr('src') !== 'undefined') {

		slide.next().fadeIn();

	} else {

		$('.slide:first').fadeIn();

	}

}

View Demo

📦 Download the full project files and try it locally