When working with the following code:
<input type="image" ... onLoad="this.style.opacity = 1" />
Everything seemed to be functioning well in IE, but encountered an issue in Chrome where the onLoad
event failed to trigger upon image load.
It's worth noting that the src
attribute of the input can change dynamically. When this occurs, JavaScript sets the opacity
to 0 first and utilizes appropriate transition
properties to create a fading effect as the new image loads. Additionally, the use of <input type="image">
is necessary due to server requirements for coordinates.
To address the issue, a workaround was implemented using an absolutely-positioned <img>
element which handled the onLoad
and opacity
functionality. This <img>
was positioned behind the <input>
element, which now contained a transparent GIF pixel. While this solution worked, it was not aesthetically pleasing.
Is there a reliable method to detect the successful loading of an image within an <input>
element in Chrome? Or is it similar to the challenges faced with background-image
, where detection is not feasible?
EDIT: For reference, here is a link to the corresponding Fiddle