Hi everyone,
I am a newbie Javascript programmer. I have gotten better lately and am starting creating scripts from scratch to test my knowledge.
I wrote the script below and needless to say, it does not work... yet. I know I am not far and I need someone's help to tweak my script and let me know what was wrong with.
That would be greatly appreciated. Anyone?
I have this div in the middle of a page which has an image. I want the image.src to switch to the next image every 3 seconds.
Here's my html code:
Code:
<body>
<div id="slideShow">
<img src="pic3.jpg" id="image" />
</div>
</body>
Here's my js code:
Code:
window.onload = initLoad;
function initLoad()
{
// Create a new image object
oImage = new Image;
// tie the object image object with your target id in your html code
oImage = document.getElementById("image");
//Create a new date object
var oCurrDate = new Date();
// Create a new time object
var oCurrentTime = oCurrDate.getSeconds();
//Loop through all images in the document
for(var i=0; i<document.images.length; i++)
{
//the current image remains so as long as 3 seconds or less have passed
while(oCurrentTime <= oCurrentTime + 3)
{
// if 3 seconds have not passed, your current picture remains on the screen
oImage.src = document.images[i].src;
}
}
}