亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery實(shí)現(xiàn)圖片按比例縮放示例

 更新時(shí)間:2014年07月01日 09:22:18   投稿:whsnow  
這篇文章主要介紹了通過jquery實(shí)現(xiàn)圖片按比例縮放,需要的朋友可以參考下
  <html> 
    <title></title> 
    <head></head> 
    <style> 
      .thumbnail{overflow:hidden;width:400px;height:240px;} 
    </style> 
    <script src="http://code.jquery.com/jquery-1.4.1.min.js"></script> 
    <script language="javascript"> 
      $(function(){ 
        /* 圖片不完全按比例自動(dòng)縮小 by zwwooooo */ 
          $('#content div.thumbnail img').each(function(){ 
            var x = 400; //填入目標(biāo)圖片寬度 
            var y = 240; //填入目標(biāo)圖片高度 
            var w=$(this).width(), h=$(this).height();//獲取圖片寬度、高度 
            if (w > x) { //圖片寬度大于目標(biāo)寬度時(shí) 
              var w_original=w, h_original=h; 
              h = h * (x / w); //根據(jù)目標(biāo)寬度按比例算出高度 
              w = x; //寬度等于預(yù)定寬度 
              if (h < y) { //如果按比例縮小后的高度小于預(yù)定高度時(shí) 
                w = w_original * (y / h_original); //按目標(biāo)高度重新計(jì)算寬度 
                h = y; //高度等于預(yù)定高度 
              } 
            } 
            $(this).attr({width:w,height:h}); 
          }); 
      }); 
    </script> 
    <body> 
    <div id="content"> 
      <div id="thumbnail" class="thumbnail" > 
        <img id="web" src="./midle.png"/> 
      </div> 
     </div> 
    </body> 
  </html>

相關(guān)文章

最新評(píng)論