-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
90 lines (77 loc) · 1.92 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
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
let count = 0;
if (localStorage.getItem('count') !== null) {
count = Number(localStorage.getItem('count'));
}
const value = document.querySelector('#value .number');
const btns = document.querySelectorAll('.btn');
const ml4 = {
opacityIn: [0, 1],
scaleIn: [0.2, 1],
scaleOut: 3,
durationIn: 100,
durationOut: 75,
delay: 250
};
btns.forEach(function (btn) {
btn.addEventListener('click', function (e) {
const styles = e.currentTarget.classList;
let newValue;
disableButtons();
if (styles.contains('decrease')) {
count--;
newValue = count;
} else if (styles.contains('increase')) {
count++;
newValue = count;
} else {
count = 0;
newValue = count;
}
localStorage.setItem('count', count);
animateCountChange(newValue);
});
});
function animateCountChange(newValue) {
const oldValue = value.textContent;
const newValueElement = document.createElement('span');
newValueElement.textContent = newValue;
newValueElement.classList.add('letters');
value.parentElement.appendChild(newValueElement);
anime.timeline({ loop: false })
.add({
targets: value,
opacity: 0,
scale: ml4.scaleOut,
duration: ml4.durationOut,
easing: "easeInExpo",
})
.add({
targets: newValueElement,
opacity: ml4.opacityIn,
scale: ml4.scaleIn,
duration: ml4.durationIn,
easing: "easeOutQuad",
offset: '-=200'
})
.add({
targets: value,
scale: 1,
duration: 0,
complete: function () {
value.textContent = newValue;
value.style.opacity = 1;
newValueElement.remove();
enableButtons();
}
});
}
function disableButtons() {
btns.forEach(function (btn) {
btn.style.pointerEvents = 'none';
});
}
function enableButtons() {
btns.forEach(function (btn) {
btn.style.pointerEvents = 'auto';
});
}