入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

jquery获取图片原始尺寸 (高度与宽度)示例

创建时间:2016-03-21 投稿人: 浏览次数:3794

 代码如下复制代码

var pic_real_width, pic_real_height; 
$("<img/>") // Make in memory copy of image to avoid css issues 
    .attr("src", $(img).attr("src")) 
    .load(function() { 
        pic_real_width = this.width;   // Note: $(this).width() will not 
        pic_real_height = this.height; // work for in memory images. 
    });


或者

 代码如下复制代码

var img = $(“#imgID”); //获取img元素
var picRealWidth, picRealHeight;
$(“<img/>”) // 在内存中创建一个img标记
    .attr(“src”, $(img).attr(“src”))
    .load(function() {
        picRealWidth = this.width;
        picRealHeight = this.height;
    });

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。