summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-06 21:06:56 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-06 21:06:56 +0800
commit1661e6b8bc0be78eb4c48c76cf888a51ba1ed80f (patch)
tree1243180da58ce94ed93c5c5bdc7d7b41683c2fef
parent2693b07cb91293375b0bc4086d6de5b24a6acfc8 (diff)
typing animation for index page
-rw-r--r--index.html3
-rw-r--r--src/js/hacktype.js45
2 files changed, 47 insertions, 1 deletions
diff --git a/index.html b/index.html
index 5143b0cb..2edb98bf 100644
--- a/index.html
+++ b/index.html
@@ -33,7 +33,7 @@
<div class="text">
<h2>Hello! I am</h2>
<object class="br"></object>
- <h1 class="title animate bounce animation--delay-p3s">littleblack111</h1>
+ <h1 data-value="littleblack111" class="title animate bounce animation--delay-p3s hacktype">littleblack111</h1>
<object class="br"></object>
<h2>welcome to my<br>website!</h2>
</div>
@@ -47,5 +47,6 @@
<script src="/src/js/tilt.js"></script>
<script src="/src/js/tilt.conf.js"></script>
<script src="/src/js/header.js"></script>
+ <script src="/src/js/hacktype.js"></script>
</body>
</html>
diff --git a/src/js/hacktype.js b/src/js/hacktype.js
new file mode 100644
index 00000000..932e4c78
--- /dev/null
+++ b/src/js/hacktype.js
@@ -0,0 +1,45 @@
+const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+const numbers = "1234567890";
+const special = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
+
+let interval = null;
+
+document.addEventListener("DOMContentLoaded", () => {
+ const elements = document.querySelectorAll(".hacktype");
+ let intervals = [];
+
+ function hackType() {
+ elements.forEach((element) => {
+ let iteration = 0;
+
+ intervals.push(
+ setInterval(() => {
+ element.innerText = element.innerText
+ .split("")
+ .map((letter, index) => {
+ if (index < iteration) {
+ return element.dataset.value[index];
+ }
+
+ return letters[Math.floor(Math.random() * 26)];
+ })
+ .join("");
+
+ if (iteration >= element.dataset.value.length) {
+ clearInterval(intervals.shift());
+ }
+
+ iteration += 1 / 3;
+ }, 30)
+ );
+ });
+ }
+
+ hackType(); // Call hackType initially
+
+ setInterval(() => {
+ intervals.forEach((interval) => clearInterval(interval)); // Clear existing intervals
+ intervals = []; // Reset intervals array
+ hackType(); // Call hackType again
+ }, 15000); // Repeat every 5 seconds
+});