Home >Web Front-end >JS Tutorial >How to set image size with JavaScript
How to set the image size in JavaScript: first create an HTML sample file; then import the image through img; and finally dynamically change the image size through the "setInterval(function warp(){...}" method.
The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer
How to set the image size with JavaScript?
JavaScript to change image size
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>动态改变图片大小</title> <script language="JavaScript"> window.function () { var n=2; var r=1; var control=true; setInterval(function warp(){ if(control==true){ n++; } else{ n--; } if(n==300)control=false;// if(n==1)control=true; if(control==true){ oPic.width+=1; oPic.height+=1; } else{ oPic.width-=1; oPic.height-=1; } },30);//每隔30毫秒调用一次warp函数 } </script> </head> <body bgcolor="aqua"> <img src="myImages/5.jpg" name="oPic" style="max-width:90%" alt="How to set image size with JavaScript" > <!--放在当前目录下的图片--> </body> </html>
Recommended study: "javascript Advanced Tutorial"
The above is the detailed content of How to set image size with JavaScript. For more information, please follow other related articles on the PHP Chinese website!