-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (66 loc) · 2.17 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use strict";
(function() {
window.addEventListener('load', init);
const cPalette = ['#F4B942', '#9E2A2B', '#6A994E'];
// The length of the text 'Pu Thavikulwat'
const nameLength = 14;
function init() {
qs('.overlay').style.backdropFilter = `blur(${15}px)`;
setTimeout(() => {
qs('.overlay').style.backdropFilter = `blur(${1}px)`;
}, 1000);
// qs('.overlay').style.transition = 'ease 0.3s';
window.addEventListener('scroll', handleScrollBehavior);
alternateColorText();
}
function alternateColorText() {
for (let i = 0; i < 1000; i++) {
for (let j = 1; j <= nameLength; j++) {
let txtString = 'txt-' + j;
setTimeout(() => {
id(txtString).style.color = cPalette[Math.floor(Math.random() * (cPalette.length + 1))];
}, i * 100 + j * 100);
// id(txtString).style.color = cPalette[Math.floor(Math.random() * 7)];
}
}
}
function handleScrollBehavior() {
let blurValue = 0;
if (getScrollPercent() < 5) {
blurValue = 1;
} else if (getScrollPercent() >= 5) {
blurValue = 4;
}
qs('.overlay').style.backdropFilter = `blur(${blurValue}px)`;
}
function getScrollPercent() {
var h = document.documentElement,
b = document.body,
st = 'scrollTop',
sh = 'scrollHeight';
let scrollPercent = (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100;
return scrollPercent;
}
function getMaxScrollableHeight() {
return Math.max(
document.body.scrollHeight, // Total height including overflow
document.documentElement.scrollHeight // Total height including scrollable area
) - window.innerHeight; // Subtract viewport height
}
/**
* Returns the element that has the ID attribute with the specified value.
* @param {string} id - element ID
* @return {object} DOM object associated with id.
*/
function id(id) {
return document.getElementById(id);
}
/**
* Returns the first element that matches the given CSS selector.
* @param {string} query - CSS query selector.
* @return {object[]} array of DOM objects matching the query.
*/
function qs(query) {
return document.querySelector(query);
}
})();