一段javascript实现缩略图的好代码
2013-07-01 17:20
330 查看
一段javascript实现缩略图的好代码,可以实现缩略图,代码如下
<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>
调用时,很简单,比如一段ASP代码的
<img src="../memberphoto/<%=rs("picpath")%>" align="middle" onload="DrawImage(this,200,200)"></div>
<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>
调用时,很简单,比如一段ASP代码的
<img src="../memberphoto/<%=rs("picpath")%>" align="middle" onload="DrawImage(this,200,200)"></div>
相关文章推荐
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码,可以实现缩略图
- Javascript代码 -- 去除一段string中的所有空行和空白行,内有javascript的trim实现
- 一段用JavaScript写的实现AJAX代码
- 一段实现HTML页面内定期触发事件的JavaScript代码
- 一段实现HTML页面内定期触发事件的JavaScript代码
- 一段实现选择框javascript代码的重构
- Javascript代码压缩、加密算法的破解分析及工具实现
- 用javascript实现隐藏状态栏的代码
- JavaScript可折叠区域实现代码
- Javascript实现带关闭按钮的网页漂浮广告代码
- javascript 闪烁的圣诞树实现代码
- 兼容最新firefox、chrome和IE的javascript图片预览实现代码
- 原生javascript实现图片轮播效果代码
- jq 实现上下排序的一段代码