Javascript/jQuery: How to detect img is fully downloaded or not?
问题 All I need to do is locate image at the center of its parent div. First, I tried this. $(document).ready(function() { $('#image1').css({ 'top': 50%, 'left': 50%, 'margin-top': (-$('#image1').height()/2) + 'px', 'margin-left': (-$('#image1').width()/2) + 'px' }); }); It failed cause $('#image1').height() and width() gives 0 before it is fully downloaded. So I tried to keep inspecting size of the image until it has specific width and height. like, function inspectSize() { return ($('#image1')