-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (75 loc) · 2.53 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
console.log('loaded')
function toggleMenu(){
// const allMenuItems = document.querySelectorAll('.menu-item');
// allMenuItems.forEach(item=>{
// const oldClasses = item.getAttribute('class');
// if(oldClasses.indexOf('hide')>-1){
// item.setAttribute('class',oldClasses.split('hide').join(''))
// }else{
// item.setAttribute('class',oldClasses + ' hide')
// }
// })
const menuDiv = document.getElementById('menu-items');
const oldClasses = menuDiv.getAttribute('class');
if(oldClasses.indexOf('hide')>-1){
menuDiv.setAttribute('class','animated')
}else{
menuDiv.setAttribute('class','hiding');
setTimeout(function(){
menuDiv.setAttribute('class','hide')
},300)
}
}
function scrollToEl(elementId){
const el = document.getElementById(elementId);
scrollTo({top:el.offsetTop-100, behavior:'smooth'})
}
let lastKnownScrollPosition = 0;
let ticking = false;
let cardAnimated = false;
let priceAnimated = false;
let testAnimated = false;
var isInViewport = function (elem) {
var bounding = elem.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
function doAnimation(scrollPos) {
const el_cards = document.getElementById('cards');
if(isInViewport(el_cards) && !cardAnimated){
el_cards.classList.add('animate__animated', 'animate__bounceInUp','animate__slow');
el_cards.classList.remove('hideEl');
cardAnimated = true;
}
const el_price = document.getElementById('price-cards');
let delay =0;
if(isInViewport(el_price) && !priceAnimated){
for(let e of el_price.children){
console.log(e);
e.classList.add('animate__animated', 'animate__fadeInUp',`animate__delay-${delay}s`);
e.classList.remove('hideEl');
delay++;
}
priceAnimated = true;
}
const el_test = document.getElementById('testimonials');
if(isInViewport(el_test) && !testAnimated){
el_test.classList.add('animate__animated', 'animate__fadeInRight');
el_test.classList.remove('hideEl');
testAnimated = true;
}
}
document.addEventListener('scroll', (e) => {
lastKnownScrollPosition = window.scrollY;
if (!ticking) {
window.requestAnimationFrame(() => {
doAnimation(lastKnownScrollPosition);
ticking = false;
});
ticking = true;
}
});