[英]Make element appear after scrolling
I am trying to make an element appear when the page goes past a certain Y
position, but it appears after I reload the page and then stays on the page and doesn't disappear. 我试图使元素在页面经过某个
Y
位置时出现,但是在重新加载页面后出现,然后停留在页面上并且不会消失。
var showScroll = function () {
var url = document.URL;
var urlToTest = 'http://localhost:55054/why-napit/membership-scheme-benefits';
var divEl = document.getElementById('action');
if (url == urlToTest) {
if (document.documentElement.scrollTop >= 800
|| window.pageYOffset >= 800) {
divEl.style.display = "block";
} else {
divEl.style.display = "none";
}
}
}();
window.addEventListener('load', showScroll, false);
I have tried the scroll event but doesn't work, so I assume I'm close but not close enough. 我已经尝试了滚动事件,但是没有用,所以我认为我已经接近了,但是还不够接近。
You should handle window.scroll event instead window.load 您应该处理window.scroll事件,而不是window.load
look this examples https://developer.mozilla.org/en-US/docs/Web/API/window.onscroll#Example_3.3A_Showing_a_link_to_the_top_of_the_page_after_a_scroll 看看这个例子https://developer.mozilla.org/en-US/docs/Web/API/window.onscroll#Example_3.3A_Showing_a_link_to_the_top_of_the_page_after_a_scroll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.