How to Create an Image Slider using jQuery

In this post we will show your how to create an image slider using jQuery. It is very simple and easy way to create an image slider and we need couple of line of jQuery and a little bit CSS code for that. The slider will be look like bellow.

[wp-js-fiddle url=”” style=”width:100%;height:500px;border:solid #4173A0 1px;”]

Lets follow the steps below.

Step 1

First create a html document and paste the following code save it.

<!DOCTYPE html>
	<title>FindSourceCode : Simple Image Slider</title>	
  	<link rel="stylesheet" href="css/styles.css"/>
  	<script src=""></script>

	<ul id="slider">
			<a href="">
				<img src="" alt="Alter Apfelbaum"/>
			<p>Alter Apfelbaum</p>
        	<a href="">
            	<img src="" alt="Ruth St Flowers-191"/>
        	<p>Ruth St Flowers-191</p>
        	<a href="">
            	<img src="" alt="Canada Close In."/>
        	<p>Canada Close In.</p>
	<script src="js/scripts.js"></script>

Here we in the body of the html page we add some list item. Each of these list item contains a link and inside the link element we add an image element.

Step 2

Now create a css file and put the following code segment and save it. Remember to add this stylesheet in the html page.

#slider	{ 
    border: 1px solid #008000;     
#slider li { 
#slider img {
#slider p { 
    background-color: #008000;
    opacity: 0.6;

Step 3

Now create a javascript file and put the following code segment and save it.

	$('#slider li').hide().filter(':first').show();
	setInterval(slideshow, 3000);

function slideshow() {
	$('#slider li:first').fadeOut('slow').next().fadeIn('slow').end().appendTo('#slider');

Now look at line 6 of the above code segment. Here we write a function slideshow which take the first item of the list and fadeout this and then take the next item and fade this in. Then we call a method .appendTo(“#slider) which takes the first list item and append it to the list. the .end() method ensure that it is append as the last list item. For the viewer it seems that the list is rotating and when the last list item fadeout the first list item fadein. Hopefully you understand the process. Please ask your question at the comment.

Download Source Code

Books you should read

[amazon template=findsourcecode&asin=0987153013,1449393217,1430263881]

Post Tagged with , , , ,

Leave a Reply

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

1 × four =

This site uses Akismet to reduce spam. Learn how your comment data is processed.