Last active
July 4, 2020 21:30
-
-
Save bernardchri/a32912d36bf4419c55676ccd658a65d8 to your computer and use it in GitHub Desktop.
[Add class on scroll ] #aos #animation #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
//isAnimR | |
// Ajoute une classe CSS .isAnimStart sur les éléments voulus | |
// Enleve et rajoute une classe CSS .isAnimEnd quand l'éléments apparait dans la vue | |
// utiliser comme ceci : AddClassIsAnimStart([elements]) | |
class AddClassIsAnimStart{ | |
constructor(elements){ | |
this.options = {threshold: [0.2, 0.55]} | |
this.observer = '' | |
this.elements = elements | |
} | |
anime(){ | |
this.observer = new IntersectionObserver(this.action, this.options); | |
for (let element of this.elements) { | |
this.prepare(element) | |
this.observer.observe(element); | |
} | |
} | |
prepare (item){ | |
item.classList.add("isAnimStart") | |
} | |
action (items){ | |
items.forEach((item) => { | |
if (item.intersectionRatio > 0.2){ | |
item.target.classList.remove("isAnimStart") | |
item.target.classList.add("isAnimEnd") | |
} | |
}) | |
} | |
} | |
export default AddClassIsAnimStart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment