Home > Web Front-end > HTML Tutorial > HTML implementation to obtain browser scroll distance (pure code)

HTML implementation to obtain browser scroll distance (pure code)

不言
Release: 2018-08-02 09:37:42
Original
2977 people have browsed it

This article introduces to you about the HTML implementation of obtaining the browser scrolling distance (pure code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.

/**
     * 获取浏览器滚动距离
     */
    function getScrollOffset() {
        if (window.pageXOffset) {
            return {
                x: window.pageXOffset,
                y: window.pageYOffset
            }
        } else {
            return {
                x: document.body.scrollLeft + document.documentElement.scrollLeft,
                y: document.body.scrollTop + document.documentElement.scrollTop
            }
        }
    }
    console.log(getScrollOffset());
Copy after login

Recommended related articles:

Analysis of image preloading in html (with code)

Flexible layout in HTML (Flex) Introduction (with code)

The above is the detailed content of HTML implementation to obtain browser scroll distance (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