Insert a placeholder and attach the onload event callback to the <img> element. Using jQuery
var imageElem = $('<img />'), placeholder = $('<div class="loading">Loading...</div>'); imageElem.attr('src', 'http://example.com/big_image.jpg'); $('#images').append(placeholder).append(imageElem); imageElem.hide().load(function() { placeholder.remove(); imageElem.fadeIn(); });
nanotech
source share