这篇文章主要介绍了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);
第一种要安全性要高些,保证是在图片加载完成后在获取。
感谢你能够认真阅读完这篇文章,希望小编分享jquery中获取图片真实大小的方法内容对大家有帮助,同时也希望大家多多支持天达云,关注天达云行业资讯频道,遇到问题就找天达云,详细的解决方法等着你来学习!