A little “javascript” to add in a HTML page an images rotator.
var images = new Array(10);
var index = 0;
function load_images(the_path, the_prefix, images_count)
{
var image_path_name = the_path + the_prefix;
var image_name;
var i = 1;
for (i = 1; i <= parseInt(images_count); i ++)
{
if (i < 10)
{
image_name = image_path_name + '0' + i + '.jpg';
}
else
{
image_name = image_path_name + i + '.jpg';
}
images[parseInt(i)-1] = image_name;
}
setInterval("Show_Image()",5000);
}
function Show_Image()
{
index = index + parseInt(1);
if (index > 9)
{
index = 0;
}
My_Image = document.getElementById("the_splash");
My_Image.src = images[index];
}
The function takes 3 parameters:
1) The path where the images are stored, for example “images/”.
2) The prefix of the images, for example. “gira”. The prefix of the images is used to group all the images that will rotate.
3) The number of images to display, for example “10″.
The BODY section of the HTML code to use the script:
<body onload="load_images('images/','gira',10)">
<div id="splash">
<asp:Image runat="server" ID="the_splash" />
</div>
</body>
Marchesi Dante
Advertisement