简要咨询咨询QQ网站导航网站搜索手机站点联系我们设为首页加入收藏 

Javascript限制页面图片大小

来源:易贤网   阅读:1018 次  日期:2015-04-17 14:18:29

温馨提示:易贤网小编为您整理了“Javascript限制页面图片大小”,方便广大网友查阅!

Javascript限制页面图片大小,具体代码如下:

function limitImage(ImgD){

var areaWidth = 300; //你放置图片区域的宽度。

var areaHeight = 300; //你放置图片区域的高度。

var image=new Image();

image.src=ImgD.src;

if(image.width>0 && image.height>0){

flag=true;

if(image.width/image.height>= areaWidth/areaHeight){

if(image.width>areaWidth){

ImgD.width=areaWidth;

ImgD.height=(image.height*areaWidth)/image.width;

}else{

ImgD.width=image.width;

ImgD.height=image.height;

}

ImgD.alt=image.width+"×"+image.height;

}else{

if(image.height>areaHeight){

ImgD.height=areaHeight;

ImgD.width=(image.width*areaHeight)/image.height;

}else{

ImgD.width=image.width;

ImgD.height=image.height;

}

ImgD.alt=image.width+"×"+image.height;

}

}

}

更多信息请查看IT技术专栏

更多信息请查看脚本栏目
点此处就本文及相关问题在本站进行非正式的简要咨询(便捷快速)】     【点此处查询各地各类考试咨询QQ号码及交流群
上一篇:基于AJAX.NET技术的DataGrid控件开发
下一篇:JavaScript通过setTimeout实时显示当前时间的方法
易贤网手机网站地址:Javascript限制页面图片大小
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!