Cool Image Gallery with jQuery

Here is another beautiful implementation of jQuery, an image rotator. Its a cool image gallery that displays different images in a stylish manner. It will be tempting to see it working.
View original post on Burnmind at how to create a simple automatic image rotator using jQuery.





Live Demo Download Script

jQuery Code

var images = new Array ('1.png', '2.jpg', '3.jpg', '4.gif');
var index = 1;

function rotateImage()
{
$('#myImage').fadeOut('fast', function()
{
//Sets the image at 'index' position as current image
$(this).attr('src', images[index]);

$(this).fadeIn('fast', function()
{
//Checks to see if array reached its end
if (index == images.length-1)
{
//If array reaches its end, reset the counter
index = 0;
}
else
{
index++;
}
});
});
}

$(document).ready(function()
{
setInterval (rotateImage, 2500);
});

HTML Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webspeaks.in</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="functions.js"></script>
</head>
<body>
<div id="test">
<img id="myImage" src="1.png" alt="image test" />
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</html>

CSS Code

body
{
color:#CC33CC;
background-color:#000000;
}

#test
{
margin:auto;
width: 400px;
padding:10px;
border:2px solid #d5d5d5;
}

#test img
{
float: left;
margin: 10px;
height:150px;
width:150px;
}

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.

Website: http://www.webspeaks.in/

2 thoughts on “Cool Image Gallery with jQuery

Comments are closed.