如果只有图片的URL
[size=medium]
如何获取imgStyleRule, 参考
[url]http://darrenzhu.iteye.com/admin/blogs/2065946[/url]
如果图片已经加载,可以通过如下方式获取
[/size]
function getImageDimensions(imgStyleRule) {
var defaultSize, img;
defaultSize = {
width: 10,
height: 30
};
if (!imgStyleRule || !imgStyleRule.style || !imgStyleRule.style.backgroundImage) {
return defaultSize;
}
img = new Image();
img.src = imgStyleRule.style.backgroundImage.replace(/url\(|\)$|"/ig, '');
return {
width: img.width,
height: img.height
};
}
[size=medium]
如何获取imgStyleRule, 参考
[url]http://darrenzhu.iteye.com/admin/blogs/2065946[/url]
如果图片已经加载,可以通过如下方式获取
var img = document.getElementById('imageid');
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;
[/size]