Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript image rotator issue, default image

I wrote a simple javascript image rotator which picks a random image on each page load. The issue is that if i use a default image, that default image will show up for a second before the javascript loads and replaces it. Obviously if someone has javascript disabled i want them to see an image. How can i have a default image without a flickering of the default image.

like image 310
Galen Avatar asked Mar 20 '26 22:03

Galen


1 Answers

It sounds like you want to change the page HTML before window.onload fires (because at that point the default image has been displayed already).

You need to attach your javascript function to a "DOMContentLoaded" or commonly called domready event. Dean Edwards provided us a fantastic cross-browser implementation http://dean.edwards.name/weblog/2006/06/again/.

Hope that helps :)

like image 149
Eric Wendelin Avatar answered Mar 23 '26 11:03

Eric Wendelin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!