0

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 ?

David Dutra
  • 391
  • 7
  • 21
Shai
  • 355
  • 2
  • 5
  • 18

1 Answers1

1

try this

var img = document.getElementById('imageid'); 
var width = img.clientWidth;
var height = img.clientHeight;
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263