I need some help with a rotating image. What I want is the image to rotate only when the page initially loads.
Here is the page. The image is next to the main section of text in the center.
What is happening now is the image is swapping after the page loads. I want the image to load randomly as the page loads.
Any ideas on what I did wrong in the script?
Thanks in advance.
This is happening because the window's "load" event only happens after absolutely everything has loaded, including images. So that's why you see the image that's in the hard-coded HTML first, and then the random image appears after everything has loaded.
This would be MUCH better if you do it on the server side. It would be trivial with PHP:
shuffle($arr); // $arr is the array of images, like the one in your JS
echo '<img src="' . $arr . '" alt="' . $arr . '">';
I'd definitely go with doing it on the server side.
I am going the server side with some php i found on the web also. I am a .net programmer so I am always a little weary about messing with server side code from another language I do not fully understand.