-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (47 loc) · 1.8 KB
/
app.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
const sizes = document.querySelectorAll('.size');
const colors = document.querySelectorAll('.color');
const shoes = document.querySelectorAll('.shoe');
const gradients = document.querySelectorAll('.gradient');
const shoeBg = document.querySelector('.shoeBackground');
let prevColor = "blue";
let animationEnd = true;
function changeSize(){
sizes.forEach(size => size.classList.remove('active'));
this.classList.add('active');
}
function changeColor(){
if(!animationEnd) return;
let primary = this.getAttribute('primary');
let color = this.getAttribute('color');
let shoe = document.querySelector(`.shoe[color="${color}"]`);
let gradient = document.querySelector(`.gradient[color="${color}"]`);
let prevGradient = document.querySelector(`.gradient[color="${prevColor}"]`);
if(color == prevColor) return;
colors.forEach(c => c.classList.remove('active'));
this.classList.add('active');
document.documentElement.style.setProperty('--primary', primary);
shoes.forEach(s => s.classList.remove('show'));
shoe.classList.add('show');
gradients.forEach(g => g.classList.remove('first', 'second'));
gradient.classList.add('first');
prevGradient.classList.add('second');
prevColor = color;
animationEnd = false;
gradient.addEventListener('animationend', () => {
animationEnd = true;
})
}
sizes.forEach(size => size.addEventListener('click', changeSize));
colors.forEach(c => c.addEventListener('click', changeColor));
let x = window.matchMedia("(max-width: 1000px)");
function changeHeight(){
if(x.matches){
let shoeHeight = shoes[0].offsetHeight;
shoeBg.style.height = `${shoeHeight * 0.9}px`;
}
else{
shoeBg.style.height = "475px";
}
}
changeHeight();
window.addEventListener('resize', changeHeight);