Не удаляется событие с window
Не удаляется обработчик, хотя функция передаётся одинаковая
class CheckInterection {
constructor(element) {
this.element = element;
}
get windowPosition() {
return {
top: window.scrollY,
left: window.scrollX,
bottom: window.scrollY + document.body.clientHeight,
right: window.scrollX + document.body.clientWidth,
};
}
get targetPosition() {
return {
top: window.scrollY + this.element.getBoundingClientRect().top,
left: window.scrollX + this.element.getBoundingClientRect().left,
bottom:
window.scrollY + this.element.getBoundingClientRect().bottom,
right: window.scrollX + this.element.getBoundingClientRect().right,
};
}
checkVisible() {
this._targetPosition = this.windowPosition;
this._windowPosition = this.targetPosition;
if (
this._targetPosition.bottom > this._windowPosition.top &&
this._targetPosition.top < this._windowPosition.bottom &&
this._targetPosition.right > this._windowPosition.left &&
this._targetPosition.left < this._windowPosition.right
) {
return true;
}
return false;
}
}
class AnimationText extends CheckInterection {
constructor(element) {
super(element);
this.endAnimate = false;
this.#addStyleDisableAnimation();
}
#addStyleDisableAnimation() {
this.element.style.transform = "translate(-50px, 0px)";
this.element.style.visibility = "hidden";
}
#removeStyleDisableAnimation() {
this.element.style.transform = "translate(0px, 0px)";
this.element.style.visibility = "visible";
}
animation() {
console.log(this.endAnimate);
this.visibility = this.checkVisible();
if (this.visibility) {
this.#removeStyleDisableAnimation();
this.endAnimate = true;
}
}
}
document.querySelectorAll(".title").forEach((element) => {
const animate = new AnimationText(element);
const funcrionListener = animate.animation.bind(animate)
window.addEventListener("scroll", funcrionListener);
if (animate.endAnimate) {
window.removeEventListener("scroll", funcrionListener);
}
});