Off Topic > Off Topic

Javascript Code for Rotating images?

Pages: (1/2) > >>

SuperToxic:

I need a HTML Javascript code for rotating to a random image every time the page is refreshed/visited.
I tried Googling code but they either have advertisements, don't work, or make a slideshow.
Can anybody provide me with a link? Would be appreciated!

Azimuth:

Personally I would use PHP for a task like this, but I'm too lazy write it out.

if all images have the same extension you could number them and then get a random number and do some crap with a span and innerhtml (although there is probably some way to mod the image tag that i still, dont quite remember)

Kalphiter:

You could have separate rotations from 1-4
Basically make 4 images

SuperToxic:

Could someone write out the script?
I don't know much about HTML, PHP, or Javascript.
D;

Azimuth:

If you can use PHP on your webserver, do this:
1. Put all images in a folder called images
2. Create a PHP file called image.php in the parent folder of the images (eg /sdf/images, would have image.php in /sdf/)
3. Insert below code into images.php


--- Code: ---<?php
$dir = scandir("images");
if(!$dir)
{
die("Error, directory images not found");
}
$img = rand(0,count($dir) - 1);
header("Location: images/" . $dir[$img]);
?>

--- End code ---

???
Profit

Pages: (1/2) > >>

Go to full version