Is it possible to run JavaScript before any image loads?
Is this default behavior? Dom, script, IMG load?
Javascript runs before images have loaded by default. The window
object's load
event fires when images have completed loading (for most clients; some versions of Safari have fired load
before images complete), but you're in no way obligated to wait for that event to run code.
The jQuery ready
event (as seen in another comment) fires when the DOM is assumed to be ready for complete interaction (and in some clients, the DOM is progressively ready for interaction as it is parsed). It's also not necessary, depending on what code you want to run.
load
event (and you'll want to use an abstraction around window.addEventListener()
and window.attachEvent()
, rather than assigning to window.onload
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With