Home  >  Article  >  Web Front-end  >  JavaScript dynamically changes image size_javascript skills

JavaScript dynamically changes image size_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:51:421134browse

Recently, due to project needs, when implementing images, if the image is larger than 100 X 100, it will be reduced to 100 X 100. If it is smaller than this, the original image size will be maintained. After research, it was found that it can be easily implemented using Javascript code.
Javascript code:

Copy code The code is as follows:

<script> <br>function resizeImage(obj){if(obj.height>100)obj.height=100;if(obj.width>100)obj.width=100; } <br></script>

Page code:
Copy code The code is as follows:

﹤img src="file :///E|/Pictures/22.jpg" width="385" height="350" onload="resizeImage(this)"﹥

Tested on IE6, Firefox, Google Chrome All work normally.
Statement:
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