There is a function that checks the size of the image, how to make it run after the image is loaded. Otherwise, empty parameters are returned.
2 answers
var img = document.getElementById('img'); img.onload = function() { alert('Width: ' + this.width + 'px. Height: ' + this.height + 'px'); } <img id="img" src="https://www.google.ca/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" /> |
You can assign an onload handler:
function checkSize(anImage) { alert($(anImage).width() + " x " + $(anImage).height()); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <img onload="checkSize(this)" src="https://www.google.ca/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" /> |
<img ... onload="checkSize(this)"- Igor