Home Web Front-end JS Tutorial What are the properties commonly used to obtain window size in js?

What are the properties commonly used to obtain window size in js?

Sep 08, 2017 am 09:08 AM
javascript size Attributes

window.innerHeight(innerWidth): Indicates the height (width) of the visible area. If there is a scroll bar at the bottom (right side), the height (width) of the bottom (right side) scroll bar will be calculated. Go in, This method is suitable for standard browsers and IE9+.

document.documentElement.clientHeight(clientWidth): Indicates the height (width) of the visible area. The height and width of the scroll bar will not be calculated. This method is applicable In standard browsers and lower versions of IE standard mode.

document.documentElement.offsetHeight(offsetWidth): First, offsetWidth gets the same value as clientWidth, and offsetHeight gets the height of the entire document.

Note:
I personally think that the documentElement above does not represent body. When an element has a border, element.offsetHeight contains the value of the border, but element.clientHeight does not contain the width of the border.

document.documentElement.scrollHeight(scrollWidth): Get the height and width of the full text of the web page, including the edge width.

document.body.clientHeight(clientWidth): First, the value obtained by clientWidth is equal to document.documentElement.offsetWidthCut off the body edge width, while clientHeight obtains the entire The height of the body minus the edge width.

document.body.offsetHeight(offsetWidth): The value obtained is equal to document.body.clientHeight(clientWidth) plus the width of the border of the body, that is These two values ​​get the width of the included edge.

document.body.scrollHeight(scrollWidth): Get the height and width of the full text of the web page, including the edge width.

document.body.scrollTop(scrollLeft): The distance between the top of the browser window and the top of the document (the distance between the browser window and the left side of the document), that is, the scroll bar The distance to scroll.

window.pageYOffset (pageXOffset): The distance between the top of the browser window and the top of the document (the distance between the browser window and the left side of the document), that is, the scroll bar scrolls distance.

window.screen.height(width): The height (width) of the screen resolution.

window.screen.availHeight(availWidth): Screen available work area height (width).

Let’s explain what offsetTop, clientTop, and scrollTop represent respectively:

offsetTop:The distance from the position above or the upper control, integer , unit pixel.

clientTop:The distance between the content area of ​​the element and the edge of the element, that is, the edge width of the element.

scrollTop:The distance between the top of the element window and the top of the element, that is, the distance of the scroll bar inside the element.

The above is the detailed content of What are the properties commonly used to obtain window size in js?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the size of a4 paper in centimeters? What is the size of a4 paper in centimeters? Feb 11, 2024 pm 11:51 PM

A4 paper is now used in many places, such as office, study, etc. The paper used for copying is basically A4 paper. Many friends don’t know how many centimeters the size of A4 paper is. Let’s take a look. Bar. 1. Size A4 paper is 21cm × 29.7cm (210mm × 297mm). The paper size used in most countries in the world adopts this international standard. 2. Origin A4 paper is 210mm×297mm. Reason 1: A rectangle with a length of 2 and a width of The resulting ratio is . However, 297 divided by 210, the result is 1.414, which is close to, and this ratio is exactly a piece of paper

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

What is the size of a4 paper? What is the size of a4 paper? Apr 25, 2024 am 11:55 AM

1. The aspect ratio of A4 paper is different from the common 2:3 or 3:4. Its unique ratio of √2:1 makes it stand out among many paper sizes. 2. This special ratio provides ideal visual effects and practicality for A4 paper.

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How to reduce the size of photos 'A must-see for beginners: Detailed steps to compress image size' How to reduce the size of photos 'A must-see for beginners: Detailed steps to compress image size' Feb 06, 2024 pm 06:55 PM

Many friends use cameras to record their living habits. Some professional photography friends may also use SLR cameras to take clearer photos. However, although the photos taken by SLR cameras are clear, for a photo of tens of megabytes, it will undoubtedly increase the pressure on the storage device. So, is there any way to reduce the size of the photo while retaining the details of the picture as much as possible? In fact, just compress the image. So how to compress the image size? Here are two good methods to share. Method 1: We can import the image in the beauty tool without any other processing and editing. When saving a picture, the system will provide image quality adjustment options, and we can drag the slider to adjust the retained sharpness. When the estimated size meets your needs, click Save. Method 2: ①. First open this "

bottom attribute syntax in CSS bottom attribute syntax in CSS Feb 21, 2024 pm 03:30 PM

Bottom attribute syntax and code examples in CSS In CSS, the bottom attribute is used to specify the distance between an element and the bottom of the container. It controls the position of an element relative to the bottom of its parent element. The syntax of the bottom attribute is as follows: element{bottom:value;} where element represents the element to which the style is to be applied, and value represents the bottom value to be set. value can be a specific length value, such as pixels

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

Introduction to the attributes of Hearthstone's Despair Thread Introduction to the attributes of Hearthstone's Despair Thread Mar 20, 2024 pm 10:36 PM

Thread of Despair is a rare card in Blizzard Entertainment's masterpiece "Hearthstone" and has a chance to be obtained in the "Wizbane's Workshop" card pack. Can consume 100/400 arcane dust points to synthesize the normal/gold version. Introduction to the attributes of Hearthstone's Thread of Despair: It can be obtained in Wizbane's workshop card pack with a chance, or it can also be synthesized through arcane dust. Rarity: Rare Type: Spell Class: Death Knight Mana: 1 Effect: Gives all minions a Deathrattle: Deals 1 damage to all minions

See all articles