Home >Web Front-end >JS Tutorial >How to set image size with JavaScript

How to set image size with JavaScript

藏色散人
藏色散人Original
2021-07-01 10:36:195093browse

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.

How to set image size with JavaScript

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>

How to set image size with JavaScript

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!

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