-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (55 loc) · 2.19 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
const buttonOn = document.querySelector('button[data-action="on"]');
const buttonOff = document.querySelector('button[data-action="off"]');
const selectToChangeSpeed = document.querySelector('select[name=change-speed]');
const selectToChangeIntensity = document.querySelector('select[name=change-intensity]');
const inputNumberOfGlobes = document.querySelector('input[name="number-of-globes"]');
const btnToCreateGlobes = document.querySelector('button[data-action="create-globes"]');
const createGlobes = (numberOfGlobes) => {
let result;
if (numberOfGlobes === 0) {
result = [];
} else if (numberOfGlobes >= 1) {
const div = document.createElement('div');
div.classList.add('globe');
result = [div].concat(createGlobes(numberOfGlobes - 1));
}
return result;
}
const showGlobes = (numberOfGlobes) => {
const containerGlobesElement = document.querySelector('.globes-container');
containerGlobesElement.innerHTML = '';
containerGlobesElement.append(...createGlobes(numberOfGlobes));
}
/* Events */
buttonOff.addEventListener('click', () => {
const globes = document.querySelectorAll('.globe');
[...globes].forEach(globeElement => {
globeElement.classList.add('paused-animation');
globeElement.classList.remove('running-animation');
});
});
buttonOn.addEventListener('click', () => {
const globes = document.querySelectorAll('.globe');
[...globes].forEach(globeElement => {
globeElement.classList.remove('paused-animation');
globeElement.classList.add('running-animation');
});
});
selectToChangeSpeed.addEventListener('change', () => {
const globes = document.querySelectorAll('.globe');
const speedValue = (selectToChangeSpeed.value);
[...globes].forEach(globe => {
globe.style.animationDuration = speedValue + 's';
});
});
selectToChangeIntensity.addEventListener('change', () => {
const globes = document.querySelectorAll('.globe');
const intensityValue = (selectToChangeIntensity.value);
[...globes].forEach(globe => {
globe.style.boxShadow = `2px 2px 15px ${intensityValue}px`;
});
});
btnToCreateGlobes.addEventListener('click', () => {
const numberOfGlobesValue = parseInt(inputNumberOfGlobes.value);
showGlobes(numberOfGlobesValue);
});