标题 | 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; } } } |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。