一段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="center" onload="DrawImage(this,200,200)"></div>

相关文章:

  • 2022-12-23
  • 2021-09-12
  • 2021-09-23
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
猜你喜欢
  • 2021-09-01
  • 2021-12-31
  • 2021-08-17
  • 2022-12-23
  • 2022-01-01
  • 2022-02-25
相关资源
相似解决方案