css expression 圖片自動縮放

來源:互聯網
上載者:User

我們判斷圖片超過設定大小時就會自動縮放到指定大小的expression起到關鍵作用。

<style>  
 .image {  
     max-width:600px;height:auto;cursor:pointer;  
     border:1px dashed #4e6973;padding: 3px;  
     zoom:expression( function(elm) {  
         if (elm.width>560) {  
             var oldvw = elm.width; elm.width=560;  
             elm.height = elm.height*(560 /oldvw);  
         }  
         elm.style.zoom = '1';  
     }(this));  
 }  
</style> 

<img src="test.jpg" width="990" height="2000" border="0" alt="" class="image"> 

當一張圖片超過指定寬度時,則會進行自動縮放顯示。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.