jQuery Image Slideshow

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

<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().

$(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 DemoDownload

Photo of Vincy, PHP developer
Written by Vincy Last updated: July 12, 2022
I'm a PHP developer with 20+ years of experience and a Master's degree in Computer Science. I build and improve production PHP systems for eCommerce, payments, webhooks, and integrations, including legacy upgrades (PHP 5/7 to PHP 8.x).

Leave a Reply

Your email address will not be published. Required fields are marked *

Explore topics
Need PHP help?