手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS控制图片等比例缩放的示例代码
JS控制图片等比例缩放的示例代码
摘要:复制代码代码如下:functionDrawImage(ImgD,FitWidth,FitHeight){varimage=newImage(...

复制代码 代码如下:

<SCRIPT language="JavaScript">

function DrawImage(ImgD,FitWidth,FitHeight){

var image=new Image();

image.src=ImgD.src;

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

if(image.width/image.height>= FitWidth/FitHeight){

if(image.width>FitWidth){

ImgD.width=FitWidth;

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

}

else{

ImgD.width=image.width;

ImgD.height=image.height;

}

}

else{

if(image.height>FitHeight){

ImgD.height=FitHeight;

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

}

else{

ImgD.width=image.width;

ImgD.height=image.height;

}

}

}

}

</script>

调用方法:

复制代码 代码如下:

<a href="admin/<? echo $rscase['path']?>" target="_blank"><img src="admin/<? echo $rscase['path']?>" alt="点击放大图片" width="180" height="180" onload='javascript:DrawImage(this,180,);' hspace="3" vspace="3" border="0" /></a>

【JS控制图片等比例缩放的示例代码】相关文章:

图片按比例缩放函数

光标定位等TextRange的操作的范例代码

js脚本学习 比较实用的基础

图片完美缩放

JS对字符串编码的几种方式使用

Jquery实现动态切换图片的方法

强制设为首页代码

CSS+JS构建的图片查看器

自适应图片大小的弹出窗口

鼠标图片振动代码

精品推荐
分类导航