-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.js
87 lines (66 loc) · 3.15 KB
/
animation.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
'use strict';
//Animation for categories
const categoryHeadphones = document.getElementById("categoryHeadphones");
const categorySpeakers = document.getElementById("categorySpeakers");
const categoryEarphones = document.getElementById("categoryEarphones");
const topProductText = document.getElementById("top-product");
const middleProductText = document.getElementById("middle-product");
const bottomProductText = document.getElementById("bottom-product");
const heroText = document.getElementById("heroTextAnimation");
const next = document.querySelector('.next');
const prev = document.querySelector('.prev');
const hero = document.querySelector('.hero');
const heroCredit = document.querySelector('.hero-copyright');
window.addEventListener('load', function () {
heroText.classList.add('animate-from-left');
hero.classList.add('lightText');
// heroCredit.innerHTML = credit.first;
});
window.addEventListener('scroll', function () {
let windowScrollOffset = window.innerHeight;
console.log(categoryHeadphones.getBoundingClientRect());
if (categoryHeadphones.getBoundingClientRect().top < windowScrollOffset) {
categoryHeadphones.classList.add('animate-categories');
categorySpeakers.classList.add('animate-categories');
categoryEarphones.classList.add('animate-categories');
}
if (topProductText.getBoundingClientRect().top < windowScrollOffset) {
topProductText.classList.add('animate-from-right');
}
if (middleProductText.getBoundingClientRect().top < windowScrollOffset) {
middleProductText.classList.add('animate-from-left');
}
if (bottomProductText.getBoundingClientRect().top < windowScrollOffset) {
bottomProductText.classList.add('animate-from-right');
}
});
//HERO SLIDDER
//buttons
next.addEventListener('click', function(){
const slide = document.querySelector('.active');
const firstSlide = document.querySelector('.slide-one'); //the first slide, so that we can reset the slider
slide.classList.replace("active","inactive");
// if the element has a nextElementSibling, we make it active. If it is the last element on our slider, we
// reset the slider by setting the first element as active.
if(slide.nextElementSibling){
slide.nextElementSibling.classList.replace("inactive", "active");
hero.classList.add("darkText");
} else{
firstSlide.classList.replace("inactive", "active");
hero.classList.replace("darkText", "lightText");
}
});
prev.addEventListener('click', function(){
const slide = document.querySelector('.active');
const lastSlide = document.querySelector('.slide-three'); //the last slide
slide.classList.replace("active","inactive");
// if the element has a previousElementSibling, we make it active. Otherwise, we set the last element
// (lastSlide) of our content as active.
if(slide.previousElementSibling){
slide.previousElementSibling.classList.replace("inactive", "active");
hero.classList.replace("darkText", "lightText");
} else{
lastSlide.classList.replace("inactive", "active");
hero.classList.replace("lightText", "darkText");
}
});