-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscroll.js
More file actions
38 lines (33 loc) · 1.27 KB
/
scroll.js
File metadata and controls
38 lines (33 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Web CV Designed by Muhamed Porić.
This CV is a Portfolio piece in and of itself
Contact me: contact@muhamedporic.dev
*/
// Select all the elements you want to animate
let elements = document.querySelectorAll('.progress11');
// Options for the Intersection Observer
let options = {
root: null, // relative to document viewport
rootMargin: '0px', // margin around root. Values are similar to css property. Unitless values not allowed
threshold: 0.1 // visible amount of item shown in relation to root
};
// Callback function for the Intersection Observer
let callback = (entries, observer) => {
entries.forEach((entry) => {
// If the element is in the viewport, add the animation class
if(entry.isIntersecting){
entry.target.classList.add('growWidth');
entry.target.classList.add('countUp');
} else {
// If the element is not in the viewport, remove the animation class
entry.target.classList.remove('growWidth');
entry.target.classList.remove('countUp');
}
})
};
// Create the Intersection Observer and pass in the callback
let observer = new IntersectionObserver(callback, options);
// Attach the Intersection Observer to each element
elements.forEach(element => {
observer.observe(element);
});