Reputation: 357
For the purpose of loading images in background I use $.each to iterate the fNames array which holds the images paths. For each of the loaded images I get 0 for width and height in the load method. Code follows -
$.each(fNames, function (a, b) {
var imm = new Image();
$(imm).load(function () {
var w = $(this).width();
var h = $(this).height();
console.log(b + " --> " + w + " X " + h);
$(this).appendTo("#imgList");
})
.click(function () {
$(".dialogImage").css("border", "none");
$(this).css("border", "2px solid black");
selectedImage = b;
})
.addClass("dialogImage")
.attr({
"src": "/customers/" + $("#IDHiddenField1").val() + "/" + $("#projectIDHiddenField1").val() + "/" + b,
"title": b
});
});
How can I get width and height of the loaded images ?
Upvotes: 0
Views: 39
Reputation: 176956
try this
var img = document.getElementById('imageid');
var width = img.clientWidth;
var height = img.clientHeight;
Upvotes: 1