一段javascript实现缩略图的好代码,可以实现缩略图
2007-09-16 22:46
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="../Images/<%=rs("picpath")%>" align="center" 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="../Images/<%=rs("picpath")%>" align="center" onload="DrawImage(this,200,200)"></div>
相关文章推荐
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- 一段javascript实现缩略图的好代码
- Javascript代码 -- 去除一段string中的所有空行和空白行,内有javascript的trim实现
- ESC之ESC.wsf可以实现javascript的代码压缩附使用方法第1/5页
- Javascript 代码也可以变得优美的实现方法
- ESC之ESC.wsf可以实现javascript的代码压缩附使用方法第1/5页
- C#编码中,打印预览DataGridView的一段代码,稍作了修改,可以实现。
- 一段用JavaScript写的实现AJAX代码
- 一段实现HTML页面内定期触发事件的JavaScript代码
- 一段实现HTML页面内定期触发事件的JavaScript代码
- jsp里面,实现跳转,可以在javascript里面,添加代码:
- Javascript 代码也可以变得优美的实现方法
- 一段实现选择框javascript代码的重构
- 在Javascript(js)或Jquery中直接实现超链接跳转代码示例!
- JavaScript实现图片滑动切换的代码示例分享
- Qt webKit可以做什么(四)——实现本地QObject和JavaScript交互