【问题标题】:get image width and height within $.each获取 $.each 内的图像宽度和高度
【发布时间】:2017-09-13 20:21:31
【问题描述】:

为了在后台加载图像,我使用 $.each 来迭代保存图像路径的 fNames 数组。对于每个加载的图像,我在 load 方法中的宽度和高度都为 0。 代码如下 -

$.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
    });
});

如何获取加载图像的宽度和高度?

【问题讨论】:

    标签: jquery load


    【解决方案1】:

    试试这个

    var img = document.getElementById('imageid'); 
    var width = img.clientWidth;
    var height = img.clientHeight;
    

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 2011-11-26
      • 2011-01-02
      • 2014-07-15
      • 1970-01-01
      相关资源
      最近更新 更多