用javascript自动缩小超出大小的图片
浏览:2919 类型:程序语言 发布人:Mykame 发布日期:2010/6/28 11:34:04
<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 200/200){
if(image.width>200){
ImgD.width=200;
ImgD.height=(image.height*200)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>200){
ImgD.height=200;
ImgD.width=(image.width*200)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
//-->
</script>
把上边的这段代码加入<head></head>之中
在相关图片上加入以下代码或者把onload的代码加入到body里:
<img src=# onload=javascript:DrawImage(this); >
上一篇:javascript下拉菜单 下一篇:CSS在线编辑器发布
其它相关文章
您没有ASPEncodeDLL.AspCoding 对象的操作权限或该对象不存在,请联系服务器管理员 解决方法
sql server “不允许保存更改,您所做的更改要求删除并重新创建以下表”错误的解决办法
WIN2003 IIS6 Request 对象 错误 'ASP 0104 : 80004005' 不允许操作|IIS6取消限制上传超200KB文件方法