【发布时间】:2021-09-13 17:54:30
【问题描述】:
我有以下代码:
document.addEventListener("scroll", inView);
function inView() {
if (document.getElementById("viewElement").getBoundingClientRect().bottom <= window.innerHeight) {
let top = document.querySelector("#top");
top.style.display = "block";
}
else{
top.style.display = "none";
}
}
这个函数的作用是,当用户滚动并且页脚元素在视图中时,它显示一个具有静态位置的元素。当页脚不在视野范围内时,我想隐藏元素。最好的方法是什么?
【问题讨论】:
标签: javascript scroll display