zoukankan      html  css  js  c++  java
  • 一段javascript实现缩略图的好代码,可以实现缩略图

         一段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>

  • 相关阅读:
    分形之城
    【SDOI2011 第2轮 DAY1】消防 树上问题+二分+贪心
    【Usaco Nov08 Gold】玩具 三分+贪心
    分治 复习
    快读板子
    最小线段覆盖 C神奇项链
    比赛经验积累1
    字符串 专题
    界面小项目之W3C
    前端小基础
  • 原文地址:https://www.cnblogs.com/pccai/p/895177.html
Copyright © 2011-2022 走看看