当页面滚动某个地方,就显示,否则隐藏
点击可以返回顶部
// 返回顶部模块制作
var goBack = document.querySelector(".goBack");
var nav = document.querySelector("nav");
window.addEventListener("scroll", function () {
if (window.pageYOffset >= nav.offsetTop) {
goBack.style.display = "block";
} else {
goBack.style.display = "none";
}
goBack.addEventListener("click", function () {
window.scroll(0, 0);
});