waitforimages

Javascript/jQuery: How to detect img is fully downloaded or not?

[亡魂溺海] 提交于 2019-12-21 18:49:22
问题 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')

waitForImages for background-image

 ̄綄美尐妖づ 提交于 2019-12-11 07:37:55
问题 This is the part of the image I found with browsers inspector and I want to get recognized by waitforImages: <div class="jtpl-background-area jqbga-container jqbga-web--image" background-area="" style="background-image: url('https://image.jimcdn.com/app/cms/image/transf/dimension=767x/path/s4354a59fbfee63e4/backgroundarea/ibb91266a7f033fa3/version/1529172695/image.jpg');background-position: 54.0833% 41.0025%;"></div> Already tried it with $('.jtpl-background-area'), $('.jqbga-container') or $

Javascript/jQuery: How to detect img is fully downloaded or not?

三世轮回 提交于 2019-12-04 09:38:25
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').width() != 0); } function setPosition() { if(!inspectSize()) { setTimeout(setPosition, 1000); return; }