I'm trying to implement parallax with intersectionObserver API which calls eventListener scroll function with callback. The problem is what I want to pass parameter "entry.target" to add and removeEventListener functions, is it possible to remove event listener callback with parameter?. Currently I have:
const parallaxScroll = trg => {
trg.style.top = `${-trg.getBoundingClientRect().top / 7.3}px`;
}
const addParallax = ([entry]) => {
if(entry.isIntersecting){
window.addEventListener('scroll', parallaxScroll);
//what I want to:
window.addEventListener('scroll', parallaxScroll(entry.target));
}else{
window.removeEventListener('scroll', parallaxScroll);
//what I want to:
window.removeEventListener('scroll', parallaxScroll(entry.target));
}
}
addParallax? If many times, then don't you risk to create many event handlers for scroll that all get executed on a scroll event?