function CheckImg(img)
{
var MaxWidth=400;//设置图片宽度界限
var MaxHeight=400;//设置图片高度界限
var HeightWidth=img.offsetHeight/img.offsetWidth;//设置高宽比
var WidthHeight=img.offsetWidth/img.offsetHeight;//设置宽高比
/*if(img.readyState!="complete"){
return false;//确保图片完全加载
}*/
if(img.offsetWidth>MaxWidth){
img.width=MaxWidth;
img.height=MaxWidth*HeightWidth;
}
if(img.offsetHeight>MaxHeight){
img.height=MaxHeight;
img.width=MaxHeight*WidthHeight;
}
}
限制图片大小
猜你喜欢
转载自blog.csdn.net/liuyingsv/article/details/50914435
今日推荐
周排行