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

How to set image size with JavaScript

藏色散人
Release: 2021-07-01 10:36:19
Original
5138 people have browsed it

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>
Copy after login

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!

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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template