本文收集常用的函数。
一、等比缩放函数。
/*
×××等比缩放函数×××,9种判断条件
xh:新高
xw:新宽
oldH:容高
oldW:容宽
LoadImgH:原高
LoadIngW:原宽
*/

function Scale() {
   if (LoadImgH == oldH && LoadImgW == (oldW/2)) { //1.正常显示
    xh = LoadImgH;
    xw = LoadImgW;
  }
   if (LoadImgH == oldH && LoadImgW>(oldW/2)) { //2、原高==容高,原宽>容宽 以原宽为基础
    xw = (oldW/2);
    xh = LoadImgH*xw/LoadImgW;
  }
   if (LoadImgH == oldH && LoadImgW<(oldW/2)) { //3、原高==容高,原宽<容宽  正常显示    
    xw = LoadImgW;
    xh = LoadImgH;
  }
   if (LoadImgH>oldH && LoadImgW == (oldW/2)) { //4、原高>容高,原宽==容宽 以原高为基础    
    xh = oldH;
    xw = LoadImgW*xh/LoadImgH;
  }
   if (LoadImgH>oldH && LoadImgW>(oldW/2)) { //5、原高>容高,原宽>容宽            
     if ((LoadImgH/oldH)>(LoadImgW/(oldW/2))) { //原高大的多,以原高为基础
      xh = oldH;
      xw = LoadImgW*xh/LoadImgH;
    } else { //以原宽为基础
      xw = (oldW/2);
      xh = LoadImgH*xw/LoadImgW;
    }
  }
   if (LoadImgH>oldH && LoadImgW<(oldW/2)) { //6、原高>容高,原宽<容宽 以原高为基础        
    xh = oldH;
    xw = LoadImgW*xh/LoadImgH;
  }
   if (LoadImgH//7、原高<容高,原宽=容宽 正常显示        
    xh = LoadImgH;
    xw = LoadImgW;
  }
   if (LoadImgH(oldW/2)) { //8、原高<容高,原宽>容宽 以原宽为基础    
    xw = (oldW/2);
    xh = LoadImgH*xw/LoadImgW;
  }
   if (LoadImgH//9、原高<容高,原宽<容宽//正常显示    
    xh = LoadImgH;
    xw = LoadImgW;
  }
}