怎样防上网页中图片过大撑破布局
- 提问者网友:爱了却不能说
- 2021-05-02 08:55
- 五星知识达人网友:爱难随人意
- 2021-05-02 09:08
<img src="......." onload="javascript:ImgReSize(this)" />
function ImgReSize(e)
{
if(e.width>620)
{
e.width=620;
}
}
- 1楼网友:我住北渡口
- 2021-05-02 10:40
- 2楼网友:平生事
- 2021-05-02 09:35
<script> var scaleImage = function(o, w, h){ var img = new Image(); img.src = o.src; if(img.width >0 && img.height>0) { if(img.width/img.height >= w/h) { if(img.width > w) { o.width = w; o.height = (img.height*w) / img.width; } else { o.width = img.width; o.height = img.height; } o.alt = img.width + "x" + img.height; } else { if(img.height > h) { o.height = h; o.width = (img.width * h) / img.height; } else { o.width = img.width; o.height = img.height; } o.alt = img.width + "x" + img.height; } } } </script>