-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
70 lines (55 loc) · 1.54 KB
/
script.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
//Slide-in on scroll
const slideElementsToShow = document.querySelectorAll('.slider');
const options = {
threshold: 0.5,
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) {
return;
}
entry.target.classList.add('show');
observer.unobserve(entry.target);
});
}, options);
slideElementsToShow.forEach((elem) => {
observer.observe(elem);
});
//Console animation
const elementsToShow = document.querySelectorAll('.add-element');
const elementToHide = document.querySelector('.remove-element');
function hideELement() {
setTimeout(() => {
elementToHide.classList.add('hide');
}, 800);
}
let timeoutArray = [];
function timeoutAdd(id, query, time) {
timeoutArray[id] = setTimeout(() => {
query.classList.remove('hide');
}, time);
}
function clearTimeoutArray(arr) {
for (timeout in arr) {
clearTimeout(timeout);
}
}
function handleAutoSetTimeout(arr) {
timeoutRemove = hideELement();
arr.forEach(([id, element, time]) => {
timeoutAdd(id, element, time);
});
}
let msArray = [];
let idQueryTime = [];
msArray = [
300, 1200, 1500, 1800, 1900, 2000, 2100, 2400, 2900, 3200, 3300, 3800, 3900,
4000, 4300, 5000,
];
for (let i = 0, n = elementsToShow.length; i < n; i++) {
idQueryTime.push([i, elementsToShow[i], msArray[i]]);
}
window.addEventListener('load', handleAutoSetTimeout(idQueryTime));
window.removeEventListener('load', handleAutoSetTimeout(idQueryTime));
clearTimeout(timeoutRemove);
clearTimeoutArray(timeoutArray);