I'm lazyloading an ad into my website, and I can get it to show up only when the user scrolls down far enough, but when the user scrolls back up, the div disappears. I want it so that when the user sees the div for the first time, the ads come and stay there even if he scrolls away. I also don't want the ads refreshing. My code is:
export const handleAds = () => {
var myAds;
window.addEventListener("load", function(event){
myAds = document.querySelector("#theDiv");
createObserver();
},false);
function createObserver(){
var observer;
var options = {
root: null,
rootMargin: "0px",
threshold: 0.2
};
observer = new IntersectionObserver(handleIntersect, options);
observer.observe(myAds);
}
function handleIntersect(entries,observer){
for (var i = 0; i < entries.length; i++){
if(entries[i].isIntersecting){
//ad script
}
}
}
}