Debt Consolidation - Kamala Harris - Links of Movies - Article directory - Property in Panama

PDA

View Full Version : Switch image only once at a timed interval?


Gatorade
Jul 8th 2008, 2:52 am
I have two images. I need to show the first for 5 seconds and then switch to the second image and stay. I don't need the images to keep rotating.

Could someone please show me the code for this? Positive rep for anyone that can help. :)

VishalVasani
Jul 8th 2008, 3:29 am
Hello,

Following is the script for you. Checked it.

<html>
<head>

</head>

<body onLoad="startTime()">
<img name="imgstar" src="images/1.jpg" border="0">
<script type="text/javascript">
var icount =1;
function startTime()
{


t=setTimeout('startTime()',5000);
icount = icount + 1;
if (icount == 3)
exit();

document.imgstar.src="images/"+icount+".jpg";

}


</script>
</body>

</html>


You can increase the time in milisecond using setTimeout('startTime()',5000); function.

Gatorade
Jul 8th 2008, 5:30 am
Where do I enter the second image path?

MMJ
Jul 8th 2008, 10:15 am
Its better to set the first parameter of setTimeout to a function reference, not a string.

VishalVasani
Jul 8th 2008, 11:06 am
Hello
You only required to put two images in image folder named it 1.jpg & 2.jpg.
Then this script will work for you.