Home > Article > Web Front-end > Pure js to realize adaptive size of images in div (tested, compatible with Firefox)_javascript skills
The function implemented by this code is that when we encounter a div that contains an img, when the size of the img image is unknown and the size of the div is unknown, the image will adapt to the size. When the image itself is smaller than the size of the div container, no processing will be done. Because if stretched, the picture may be distorted.
Without further ado, let’s go straight to the code. It has been tested and is compatible with Firefox, Google, IE6, IE7/8
The following is the js code: