欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery實現圖片按比例縮放示例

 更新時間:2014年07月01日 09:22:18   投稿:whsnow  
這篇文章主要介紹了通過jquery實現圖片按比例縮放,需要的朋友可以參考下
  <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(){ 
        /* 圖片不完全按比例自動縮小 by zwwooooo */ 
          $('#content div.thumbnail img').each(function(){ 
            var x = 400; //填入目標圖片寬度 
            var y = 240; //填入目標圖片高度 
            var w=$(this).width(), h=$(this).height();//獲取圖片寬度、高度 
            if (w > x) { //圖片寬度大于目標寬度時 
              var w_original=w, h_original=h; 
              h = h * (x / w); //根據目標寬度按比例算出高度 
              w = x; //寬度等于預定寬度 
              if (h < y) { //如果按比例縮小后的高度小于預定高度時 
                w = w_original * (y / h_original); //按目標高度重新計算寬度 
                h = 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>

相關文章

最新評論