Home > Web Front-end > JS Tutorial > body text

Pure js to realize adaptive size of images in div (tested, compatible with Firefox)_javascript skills

WBOY
Release: 2016-05-16 16:44:23
Original
1200 people have browsed it

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:

Copy code The code is as follows:



The following is the html code:
Copy Code The code is as follows:



The following is the css code:
Copy code The code is as follows:

.sy_pic{ width:200px; height:300px; border:#000 solid 5px; text-align:center;}

Change the image address yourself. If you have any questions or advice, please join the QQ group: 255708401.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template