×
新网 > 建站推广 > 正文

jquery中如何获取图片真实大小

  • 作者:zccc
  • 来源:网络
  • 2020-11-18 12:05:07

jquery中获取图片真实大小的方法:1、方法一【.attr("src", $(''#imgid").attr("src"))】;2、方法二【theImage.src = $(''#imgid").attr( "src");】。jquery

jquery中获取图片真实大小的方法:1、方法一【.attr("src", $(\'\'#imgid").attr("src"))】;2、方法二【theImage.src = $(\'\'#imgid").attr( "src");】。

 

jquery中获取图片真实大小的方法:

第一种:

$("<img/>") // Make in memory copy of image to avoid css issues  在内存中创建一个img标记
    .attr("src", $(\'\'#imgid").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 theImage = new Image(); 
theImage.src = $(\'\'#imgid").attr( "src"); 
alert( "Width: " + theImage.width); 
alert( "Height: " + theImage.height);

第一种要安全性要高些,保证是在图片加载完成后在获取。

  • 相关专题

免责声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,也不承认相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,请发送邮件至:operations@xinnet.com进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

免费咨询获取折扣

Loading