scroll2078

navigation bar behavior based on scroll bar

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

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

  1. document.addEventListener('DOMContentLoaded', function () {
  2. const header = document.querySelector('.header');
  3. header.style.top = '-18px'; // Initial position of the header
  4.  
  5. function handleScroll() {
  6. let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  7.  
  8. if (scrollTop <= 18) {
  9. header.style.top = `${-18 + scrollTop}px`;
  10. } else {
  11. header.style.top = '0px';
  12. }
  13. }
  14.  
  15. window.addEventListener('scroll', handleScroll);
  16. });