Created
November 16, 2014 09:17
-
-
Save pH200/21a78e99408a650062c5 to your computer and use it in GitHub Desktop.
Image size getter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function imageSizeGetter(image: HTMLImageElement, callback: (size:[number, number]) => any): void { | |
if (image.width > 0 && image.height > 0) { | |
callback([image.width, image.height]); | |
} else { | |
var observer = new MutationObserver(function (record) { | |
observer.disconnect(); | |
callback([image.width, image.height]); | |
}); | |
observer.observe(image, { | |
attributes: true, | |
attributeFilter: ["width", "height"] | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment