Answers for "intersectionobserver threshold"

1

intersection observer example

const images = document.querySelectorAll('.lazyload');

function handleIntersection(entries) {
  entries.map((entry) => {
    if (entry.isIntersecting) {
      entry.target.src = entry.target.dataset.src;
      entry.target.classList.add('loaded')
      observer.unobserve(entry.target);
    }
  });
}

const observer = new IntersectionObserver(handleIntersection);

images.forEach(image => observer.observe(image));
Posted by: Guest on January-20-2021
0

intersectionobserver threshold

const box = document.querySelector(".box");
const callbackFunction = function(entries){
  	if(entries[0].isIntersecting) { 
    	entries[0].target.children[0].classList.add("changeColor");
      	// Stop observating because we made the Element appear
    	observer.unobserve(fadeElement);
  	}
};

const observer = new IntersectionObserver(callbackFunction, {
	// Here you can add some Options you can find on the documentation
  	threshold: [0.5] // The Function triggers when you can see 50% of the Element
});
observer.observe(box)
Posted by: Guest on October-15-2021

Code answers related to "intersectionobserver threshold"

Code answers related to "Javascript"

Browse Popular Code Answers by Language