Javascript Image Resize

前端 未结 13 1493
南旧
南旧 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:48

    okay it solved, here is my final code

    if($(this).width() > $(this).height()) { 
     $(this).css('width',MaxPreviewDimension+'px');
     $(this).css('height','auto');
    } else {
     $(this).css('height',MaxPreviewDimension+'px');
     $(this).css('width','auto');
    }
    

    Thanks guys

提交回复
热议问题