我目前正在做一个项目,用户希望能够在header
上的汉堡包按钮不可见时打开侧边栏。为了完成这个任务,我做了一个按钮,只有当header
不在视图中时才显示。问题是,showSidebar
功能没有被执行。我还试图将showSidebar
的功能直接作为匿名函数导入到addEventListener
中,结果相同。
每当我点击任何不在边栏或汉堡按钮本身的东西时,边栏就会关闭。
function showSidebar() {
sidebar.classList.add('show');
overlay.classList.add('enabled');
}
function togglePill() {
const scrolled = window.scrollY;
if (scrolled <= 69) {
locationPill.classList.remove('show');
} else if (scrolled > 69) {
locationPill.classList.add('show');
locationPill.addEventListener('click', showSidebar);
}
}
window.addEventListener('scroll', togglePill);
字符串
1条答案
按热度按时间5gfr0r5j1#
确保当你点击位置药丸时隐藏侧边栏功能没有被切换
字符串