wangtianbao

          等比例改變圖片大小

          function imgSize(ImgD, iwidth, iheight) {
           var image = new Image();
           image.src = ImgD.src;
           if (image.width > 0 && image.height > 0) {
            if (image.width / image.height >= iwidth / iheight) {
             if (image.width > iwidth) {
              ImgD.width = iwidth;
              ImgD.height = (image.height * iwidth) / image.width;
             } else {
              ImgD.width = image.width;
              ImgD.height = image.height;
             }
            } else {
             if (image.height > iheight) {
              ImgD.height = iheight;
              ImgD.width = (image.width * iheight) / image.height;
             } else {
              ImgD.width = image.width;
              ImgD.height = image.height;
             }
            }
           }
          }

          function changeAllImage(iwidth, iheight){
           var imgs = document.images;
           for (j=0; j<imgs.length; j=j+1){
            var img = document.images[j];
            imgSize(img, iwidth, iheight);
           }
          }


          =======================

          引用:
          <img src='001.jpg' onload='imgSize(this, 143, 200)'/>
          以上操作會產(chǎn)生 Undefined attribute name (onload). 警告

          可以:
          <body onload=' changeAllImage(143, 200)' >
          ……
          <image src='001.jpg' />
          ……
          </body>

          posted on 2011-11-17 15:53 王添寶 閱讀(151) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 祁东县| 阿拉善盟| 观塘区| 永仁县| 鲁甸县| 福建省| 西宁市| 安吉县| 潍坊市| 武宁县| 应用必备| 江山市| 磐安县| 武义县| 大田县| 枝江市| 双峰县| 张家界市| 洛阳市| 舞钢市| 潮安县| 永昌县| 丁青县| 信阳市| 馆陶县| 兴安县| 繁昌县| 长武县| 金湖县| 洛隆县| 邳州市| 渝北区| 黔南| 望奎县| 龙州县| 呼伦贝尔市| 聂拉木县| 延吉市| 平原县| 太白县| 鄯善县|