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)'/>
          以上操作會產生 Undefined attribute name (onload). 警告

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

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


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


          網站導航:
           
          主站蜘蛛池模板: 金沙县| 汽车| 和平区| 青阳县| 巴林右旗| 鞍山市| 子长县| 武鸣县| 甘德县| 珲春市| 孟津县| 金塔县| 方山县| 五原县| 邵东县| 乐业县| 廉江市| 博兴县| 博罗县| 修武县| 增城市| 马尔康县| 基隆市| 宣汉县| 明光市| 长子县| 普格县| 土默特左旗| 农安县| 庆阳市| 砀山县| 攀枝花市| 新巴尔虎左旗| 齐齐哈尔市| 乌兰县| 绥棱县| 获嘉县| 安化县| 天全县| 龙州县| 剑阁县|