This article describes the method of limiting the display size of images in JavaScript. Share it for your reference. The specific implementation method is as follows:
/** * Limit the size of the image display. * * @param thisobj Image component * @param limitW limits width size * @param limitH Limit height size */ function imageResize(thisobj, limitW, limitH) { var newW; var newH; if ( > limitW) { newW = limitW; newH = parseInt( * newW / ); // Scale by width if (newH > limitH) { newH = limitH; newW = parseInt( * newH / ); } = newW; = newH; } else if ( > limitH) { newH = limitH; newW = parseInt( * newH / ); = newW; = newH; } }
I hope this article will be helpful to everyone's JavaScript programming.