javascript - 未捕获的类型错误:无法读取 chrome 未注册的 null 属性“classList”(试图显示和消失标题)
问题描述
IDK 有什么问题,但是 chrome 说即使我的所有设置都完全按照视频所描绘的那样设置,但无法读取分类器 PS:我是 Coding 的初学者,所以 IDK 为什么它没有被 chrome 读取。
我希望发生的是添加一个标题,然后使标题出现和消失,但它在 Codepen 上完美运行,但不是 chrome 你能解释为什么吗?
var doc = document.documentElement;
var w = window;
var prevScroll = w.scrollY || doc.scrollTop;
var curScroll;
var direction = 0;
var prevDirection = 0;
var Header = document.getElementById('site-header');
var checkScroll = function() {
/*
** Find the direction of scroll
** 0 - initial, 1 - up, 2 - down
*/
curScroll = w.scrollY || doc.scrollTop;
if (curScroll > prevScroll) {
//scrolled up
direction = 2;
}
else if (curScroll < prevScroll) {
//scrolled down
direction = 1;
}
if (direction !== prevDirection) {
toggleHeader(direction, curScroll);
}
prevScroll = curScroll;
};
var toggleHeader = function(direction, curScroll) {
if (direction === 2 && curScroll > 92) {
//replace 52 with the height of your header in px
Header.classList.add("hide");
prevDirection = direction;
}
else if (direction === 1) {
Header.classList.remove("hide");
prevDirection = direction;
}
};
window.addEventListener('scroll', checkScroll);
})();```
解决方案
推荐阅读
- php - 更改默认目录 orderby 会删除 WooCommerce 中的 menu_order 选项
- time - 如何解析自纪元以来格式为微秒的时间戳?
- javascript - React Hooks 更新字典状态
- unity3d - Unity3D:使用上传证书 SHA 密钥将游戏发布到 Play 商店,因此排行榜不适用于用户
- bash - 为什么在输出完成之前会出现自定义 bash 提示?
- swiftui-list - 如何在swiftUI中将背景颜色添加到列表中
- swift - 替代不带标识符的 shouldPerformSegue
- sql - 将表 A 中的每一行与表 B 中的一行相关联,环绕
- python - 使用 PyoDBC 和 docker-compose 从 Python 应用程序连接到 Postgresql 数据库
- javascript - 如何使用 Ramda.js 展平嵌套对象?