工作小知识积累(1)-- 获取图片的大小

1、获取图片大小的函数getImageSize

function getImageSize(imageEl) {
	var i = new Image(); //新建一个图片对象
	i.src = imageEl.src;   //将图片的src属性赋值给新建图片对象的src
	return new Array(i.width, i.height); //返回图片的长宽像素
	//return [i.width, i.height];
}

2、示例

var imgEl = document.getElementById(imgEl),
	imgSize = getImageSize(imgEl),
	imgWidth = imgSize[0],  //取得图片的宽度
	imgHeight = imgSize[1]; //取得图片的高度

  

posted @ 2011-09-07 09:23  张臣  阅读(436)  评论(1编辑  收藏  举报