/ Published in: JavaScript
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<html>
<head>
<title>Sliding Images</title>
<script type="text/javascript">
//Create images Array
var imgArr = new Array("images/img1.jpg",
"images/img2.jpg",
"images/img3.jpg");
var count = imgArr.length; // assign images array length
var position = 0; //position is set to zero
function slidingImages() {
if ( document.images ) {
if ( position < count ) {
imageSrc(position); // call the image source
position += 1;
} else {
position = 0;
imageSrc(position);
}
}
setTimeout(slidingImages, 3000);
}
function imageSrc(position) {
document.banner.src = imgArr[position];
}
</script>
</head>
<body onload="slidingImages()">
<img src="images/img1.jpg" name="banner"/>
</body>
</html>
Comments
 Subscribe to comments
                    Subscribe to comments
                
                