Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Window.Screen to set screen width in JavaScript

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use Window.Screen to set the screen width in JavaScript. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

JavaScript uses Window.Screen to set the screen width

The screen.width property returns the width of the visitor screen in pixels.

Example

Displays the screen width in pixels:

Document.getElementById ("demo"). InnerHTML = "Screen Width:" + screen.width

The result will be:

Screen Width: 1920

Window Screen height

The screen.height property returns the height of the visitor screen in pixels.

Example

Displays the screen height in pixels:

Document.getElementById ("demo"). InnerHTML = "Screen Height:" + screen.height

The result will be:

Screen Height: 1080

Available width of Window Screen

The screen.availWidth property returns the width of the visitor's screen, minus interface features such as window toolbars in pixels.

Example

Displays the available screen width in pixels:

Document.getElementById ("demo"). InnerHTML = "Available Screen Width:" + screen.availWidth

The result will be:

Available Screen Width: 1920

Window Screen available height

The screen.availHeight property returns the height of the visitor's screen, minus interface features such as window toolbars in pixels.

Example

Displays the available height of the screen in pixels:

Document.getElementById ("demo"). InnerHTML = "Available Screen Height:" + screen.availHeight

The result will be:

Available Screen Height: 1040

Window Screen color depth

The screen.colorDepth property returns the number of bits used to display a color.

All modern computers use 24-bit or 32-bit hardware color resolution:

24 bits = 16777216 different "True Colors"

32 bits = 4294967296 different "Deep Colors"

Older computers use 14-bit: 65536 different "High Colors" resolutions.

Extraordinarily old computers and old-fashioned mobile phones use 8-bit: 256 different "VGA colors".

Example

Displays the screen color depth in bits:

Document.getElementById ("demo"). InnerHTML = "Screen Color Depth:" + screen.colorDepth

The result will be:

Screen Color Depth: 24

The # rrggbb (rgb) value used in HTML represents "True Colors" (a different color in 16777216).

Window Screen pixel depth

The screen.pixelDepth property returns the pixel depth of the screen.

Example

Displays the screen pixel depth in bits:

Document.getElementById ("demo"). InnerHTML = "Screen Pixel Depth:" + screen.pixelDepth

The result will be:

Screen Pixel Depth: 24

For modern computers, color depth and pixel depth are equal.

This is the end of this article on "how to use Window.Screen to set screen width in JavaScript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report