How to change the window size in js? How to change the window size in js

云罗郡主
Release: 2018-11-06 17:50:44
Original
15295 people have browsed it

The content of this article is about how to change the window size in js? The method of changing the window size in js has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In JavaScript, you can use the resizeTo() method or resizeBy() method of the window object to change the size of the window.

1. resizeTo() method

Syntax: window.resizeTo(x, y)

Description:

x means The changed horizontal width, y represents the changed vertical height. The units of x and y are both px. The browser comes with its own units. We only need to use numerical values.

Example:

     
Copy after login

The effect is as follows:

How to change the window size in js? How to change the window size in js

2. resizeBy() method

Syntax:

1window.resizeBy(x, y)

Description: When the values of x and y are greater than 0, it is expanded, and if it is less than When 0, it is reduced. The units of x and y are both px.

x represents the value of each expansion or reduction of the window in the horizontal direction, and y represents the value of each expansion or reduction of the window in the vertical direction.

The difference between resizeTo(x,y) and resizeBy(x,y) is that: x and y in resizeTo(x,y) are "changed" values, while in resizeBy(x,y) x, y are "increasing or decreasing" numerical values. "To" means a result, and "by" means a process. You will understand if you think about the English meanings of "to" and "by" carefully.

Example:

     
Copy after login

The preview effect in the browser is as follows:

How to change the window size in js? How to change the window size in js

Analysis:

We first click "resizeTo ” button sets the current window width to 200px and the height to 200px. Then every time we click the "resizeBy" button, we will find that the width and height of the current window will increase by 50px. This is all due to the result of window.resizeBy(50,50).

The above is a complete introduction to how to change the window size in js? How to change the window size in js. If you want to know more aboutJavaScript tutorial, please pay attention to the PHP Chinese website.


The above is the detailed content of How to change the window size in js? How to change the window size in js. For more information, please follow other related articles on the PHP Chinese website!

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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!