Display image at 50% of its “native” size

前端 未结 5 848
野趣味
野趣味 2020-11-29 19:39

I\'m putting an img tag in a document without knowing the width/height of the corresponding image:


5条回答
  •  庸人自扰
    2020-11-29 20:07

    The zoom property sounds as though it's perfect for Adam Ernst as it suits his target device. However, for those who need a solution to this and have to support as many devices as possible you can do the following:

    
    

    The reason for the this.onload=null addition is to avoid older browsers that sometimes trigger the load event twice (which means you can end up with quater-sized images). If you aren't worried about that though you could write:

    
    

    Which is quite succinct.

提交回复
热议问题