Javascript Image Resize

前端 未结 13 1504
南旧
南旧 2020-11-28 23:03

Does anyone know how to resize images proportionally using JavaScript?

I have tried to modify the DOM by adding attributes height and width

13条回答
  •  误落风尘
    2020-11-28 23:46

    Use JQuery

    var scale=0.5;
    
    minWidth=50;
    minHeight=100;
    
    if($("#id img").width()*scale>minWidth && $("#id img").height()*scale >minHeight)
    {
        $("#id img").width($("#id img").width()*scale);
        $("#id img").height($("#id img").height()*scale);
    }
    

提交回复
热议问题