简体   繁体   中英

How not to dispatch addEventListener(“scroll”) when it is loaded and the initial scroll position is not at the top

This is a scroll event. It works not only when scrolling but also when the scroll position is not at the top of the screen when loading. Is there any way to keep this from igniting?

window.addEventListener("scroll",function(){
  console.log("load");
});

Try waiting until the page has entirely loaded:

window.addEventListener('load', (event) => {
    window.addEventListener("scroll", function() {
        console.log("load");
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM