scroll2078

navigation bar behavior based on scroll bar

目前为 2024-04-01 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/491240/1352510/scroll2078.js

document.addEventListener('DOMContentLoaded', function () {
    const header = document.querySelector('.header');
    header.style.top = '-18px'; // Initial position of the header

    function handleScroll() {
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop;

        if (scrollTop <= 18) {
            header.style.top = `${-18 + scrollTop}px`;
        } else {
            header.style.top = '0px';
        }
    }

    window.addEventListener('scroll', handleScroll);
});