Home > Web Front-end > HTML Tutorial > HTML implementation to obtain the width and height of the browser's visible area (pure code)

HTML implementation to obtain the width and height of the browser's visible area (pure code)

不言
Release: 2018-08-02 09:41:12
Original
2367 people have browsed it

This article introduces you to the HTML implementation of obtaining the width and height of the browser's visible area (pure code). It has certain reference value. Friends in need can refer to it. I hope it will help You helped.

/**
     * 获取浏览器可视区域宽度
     */
    function getViewPortOffset() {
        if (window.innerWidth) {
            return {
                w: window.innerWidth,
                h: window.innerHeight
            }
        } else if (document.compatMode = "BackCompat") {
            return {
                w: document.body.clientWidth,
                h: document.body.clientHeigth
            }
        } else {
            return {
                w: document.documentElement.clientWidth,
                h: document.documentElement.clientHeight
            }
        }
    }
    console.log(getViewPortOffset());
Copy after login

Recommended related articles:

html implements obtaining browser scrolling distance (pure code)

html Analysis of image preloading (with code)

The above is the detailed content of HTML implementation to obtain the width and height of the browser's visible area (pure code). 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template