-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_home.js
67 lines (54 loc) · 2.04 KB
/
app_home.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
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');
}
//escolha de cores do sapato
function changeColor(){
//clicando em uma cor a verifica a var booleana (se é vdd)
if(!animationEnd) return;
//if (!animationEnd === false)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');
//animação dos botões
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'));
//annimação do fundo
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));
//altura do sapato
let x = window.matchMedia("(max-width: 1000px)");
function changeHeight(){
//x.matches é o mesmo que @media(max-width:1000px)
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);