Here is the refined version in which you can mention a delay information to each images:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
</style>
<script type="text/javascript">
var globals = {
//You can edit the following part with the images(including path) information that you want to display and its alt value, if any
images: [{
src: 'image1.png',
alt: 'First Image',
delay: 2000
}, {
src: 'image2.gif',
alt: 'Second Image',
delay: 1000
}, {
src: 'image3.jpg',
alt: 'Third Image',
delay: 5000
}, {
src: 'image4.png',
alt: 'Fourth Image',
delay: 1000
}, {
src: 'image5.gif',
alt: 'Fifth Image',
delay: 6000
}],
//You don't have to edit anything after this in JS Code.
count: 1
}
function changeImage() {
if (globals.count === globals.images.length) {
globals.count = 0;
}
if (document.getElementById('imageContainer') && document.getElementById('imageContainer').getElementsByTagName('img')[0]) {
document.getElementById('imageContainer').getElementsByTagName('img')[0].src = globals.images[globals.count].src;
document.getElementById('imageContainer').getElementsByTagName('img')[0].alt = globals.images[globals.count].alt;
if(!globals.images[globals.count].delay){
globals.images[globals.count].delay = 1000;
}else{
globals.images[globals.count].delay = parseInt(globals.images[globals.count].delay);
}
setTimeout(function(){
changeImage();
},globals.images[globals.count].delay);
globals.count++;
}
}
window.onload = function() {
setTimeout(function(){
changeImage();
},globals.images[0].delay);
}
</script>
</head>
<body>
<div id="imageContainer">
<img src="image1.png" border="0" alt="First Image" /> <!--Mention the first image that you want to show while the page loads -->
</div>
</body>
</html>
I have highlighted my changes.
Hope this helps
Bookmarks