This article describes the method of limiting the size of image display 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 Limit the width size* @param limitH Limit the height size*/function imageResize(thisobj, limitW, limitH) { var newW; var newH; if (thisobj.width > limitW) { newW = limitW; newH = parseInt(thisobj.height * newW / thisobj.width); // Scale by width if (newH > limitH) { newH = limitH; newW = parseInt(thisobj.width * newH / thisobj.height); } thisobj.width = newW; thisobj.height = newH; } else if (thisobj.height > limitH) { newH = limitH; newW = parseInt(thisobj.width * newH / thisobj.height); thisobj.width = newW; thisobj.height = newH; }}I hope this article will be helpful to everyone's JavaScript programming.