一段javascript实现缩略图的好代码
2007-09-27 10:14
711 查看
<script language="javascript">
//显示缩略图
function DrawImage(ImgD,width_s,height_s){
/*var width_s=139;
var height_s=104;
*/
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>=width_s/height_s){
if(image.width>width_s){
ImgD.width=width_s;
ImgD.height=(image.height*width_s)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>height_s){
ImgD.height=height_s;
ImgD.width=(image.width*height_s)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
/*else{
ImgD.src="";
ImgD.alt=""
}*/
}
</script>
调用
<div><img src="图片" align="center" onload="DrawImage(this,200,200)"></div>
//显示缩略图
function DrawImage(ImgD,width_s,height_s){
/*var width_s=139;
var height_s=104;
*/
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>=width_s/height_s){
if(image.width>width_s){
ImgD.width=width_s;
ImgD.height=(image.height*width_s)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>height_s){
ImgD.height=height_s;
ImgD.width=(image.width*height_s)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
/*else{
ImgD.src="";
ImgD.alt=""
}*/
}
</script>
调用
<div><img src="图片" align="center" onload="DrawImage(this,200,200)"></div>
相关文章推荐
- 一段javascript实现缩略图的好代码,可以实现缩略图
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段实现HTML页面内定期触发事件的JavaScript代码
- Javascript代码 -- 去除一段string中的所有空行和空白行,内有javascript的trim实现
- 一段用JavaScript写的实现AJAX代码
- 一段实现选择框javascript代码的重构
- 一段实现HTML页面内定期触发事件的JavaScript代码
- javascript学习笔记(十九) 节点的操作实现代码
- JavaScript 参数调用 【每日一段代码51】
- Javascript代码压缩、加密算法的破解分析及工具实现
- 周期性循环执行一段代码的实现
- javascript trim 去空格函数实现代码
- Javascript---有趣的一段代码--this指向问题
- 用Javascript评估用户输入密码的强度实现代码
- php实现文件下载的一段代码
- JavaScript talbe表中指定位置插入一行的实现代码 脚本之家修正版 转(http://www.jb51.net/article/18502.htm)