This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
forked from madnanrizqu/madnanrizqu.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
124 lines (102 loc) · 3.33 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function heroBackground() {
// Initialising the canvas
const canvas = document.getElementById("hero_background"),
ctx = canvas.getContext("2d");
const parent = document.getElementById("hero");
// Setting the width and height of the canvas
canvas.width = parent.clientWidth;
canvas.height = parent.clientHeight;
// Setting up the letters
const letters = "01".split("");
// Setting up the columns
const fontSize = 13,
columns = canvas.width / fontSize;
// Setting up font size
ctx.font = `${fontSize}px monospace`;
// Setting up the drops
const drops = [];
for (let i = 0; i < columns; i++) {
drops[i] = 1;
}
// Setting up the draw function
function draw() {
ctx.fillStyle = "rgba(255, 255, 255, .1)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < drops.length; i++) {
const text = letters[Math.floor(Math.random() * letters.length)];
ctx.fillStyle = "rgba(31, 169, 200, 0.221)";
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
drops[i]++;
if (drops[i] * fontSize > canvas.height && Math.random() > 0.95) {
drops[i] = 0;
}
}
}
// Loop the animation
setInterval(draw, 99);
}
function heroAnimatedHeadline() {
const text = document.getElementById("hero__dynamic_text");
try {
// Set to no content to avoid jitter
text.textContent = "";
var typed = new Typed("#hero__dynamic_text", {
strings: ["smooth", "reliable", "engaging", "aesthetic", "powerful"],
typeSpeed: 100,
startDelay: 300,
loop: true,
showCursor: false,
});
} catch (error) {
text.textContent = "smooth"; // add fallback incase type.js fails to load
}
}
function initDrawerToggleListener() {
const toggler = document.getElementById("mobile_drawer_toggle");
toggler.addEventListener("click", toggleMobileDrawer);
}
function initButtonDialogListener() {
const openButtons = document.querySelectorAll("[data-open-dialog-id]");
openButtons.forEach((btn) => {
btn.addEventListener("click", () => {
const openDialogId = btn.dataset.openDialogId;
const dialog = document.getElementById(openDialogId);
dialog.showModal();
});
});
const closeButtons = document.querySelectorAll("[data-close-dialog-id]");
closeButtons.forEach((btn) => {
btn.addEventListener("click", () => {
const closeDialogId = btn.dataset.closeDialogId;
const dialog = document.getElementById(closeDialogId);
dialog.close();
});
});
}
document.addEventListener("DOMContentLoaded", () => {
heroBackground();
heroAnimatedHeadline();
initDrawerToggleListener();
initButtonDialogListener();
});
function toggleMobileDrawer() {
const toggler = document.getElementById("mobile_drawer_toggle");
const drawer = document.getElementById("mobile_drawer");
const [openIcon, closeIcon] = toggler.children;
const hideClassName = "u_hide_all";
if (closeIcon.classList.contains(hideClassName)) {
// Open drawer
// Change icons
closeIcon.classList.remove(hideClassName);
openIcon.classList.add(hideClassName);
// Show drawer
drawer.classList.remove(hideClassName);
} else {
// Close drawer
// Change icons
closeIcon.classList.add(hideClassName);
openIcon.classList.remove(hideClassName);
// Hide drawer
drawer.classList.add(hideClassName);
}
}