OK...this is simple, but I can't get this working.
I click on a button and change an image's src, i.e.
The problem is that if I have a large image, i.e. 300KB, then this doesn't work.
I would like to display an animated gif until the image has finished loading, then display the image.
My issue here is how can I tell when the image has finished loading? Seeing as I can potentially have 30+ images, it would be overkill to pre-load them all.
My only other option is Ajax, but surely this can be done just with Javascript.
I click on a button and change an image's src, i.e.
Code:
<script type="text/javascript">
function showImage(imageName)
{
var default_img = getElementById('defaultImage');
tmp_img = new Image();
tmp_img.src = imageName;
default_img.width = tmp_img.width;
default_img.height = tmp_img.height;
default_img.src = imageName;
}
</script>
<button onclick="showImage('test1.jpg');">test</button>
The problem is that if I have a large image, i.e. 300KB, then this doesn't work.
I would like to display an animated gif until the image has finished loading, then display the image.
My issue here is how can I tell when the image has finished loading? Seeing as I can potentially have 30+ images, it would be overkill to pre-load them all.
My only other option is Ajax, but surely this can be done just with Javascript.