This article describes the simple method of JavaScript to reduce images in a proportional manner. Share it for your reference, as follows:
//Equiscale image reduction function changeImg(obj,width,height) { var img = new Image(); img.src = document.getElementById(obj.id).src var ys_w = img.width; var ys_h = img.height; if(ys_w > width || ys_h > height) { var scale; var scale1 = ys_w / width; var scale2 = ys_h / height; //alert(scale1+","+scale2); if(scale1 > scale2) { scale = scale1; } else { scale = scale2; } document.getElementById(obj.id).style.width = ys_w / scale; document.getElementById(obj.id).style.height = ys_h / scale; }}For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.