Skip to content

Latest commit

 

History

History
82 lines (52 loc) · 1.49 KB

File metadata and controls

82 lines (52 loc) · 1.49 KB

Loaded

Wait until object is loaded

// async with promise resolve
const load = name => new Promise( resolve => {
  name.onload = () => resolve(true);
});
await load(window);



Wait until document ready

$(function(){ //.. })



Wait until everything is fully loaded and loading icon is gone

window.addEventListener('load', function () { //.. });



Wait until element loaded

 document.querySelector('.profile').onload = function(e){ //.. }



remove event listener from anonym function

document.querySelector('.profile').addEventListener('load', function () { 
  this.removeEventListener('load', arguments.callee);
});



Check if image exists when there was no error

	
function IsImageOk(img) {
    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (img.naturalWidth === 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}
	
IsImageOk(document.querySelector('.img'))