summaryrefslogtreecommitdiff
path: root/assets/js/morph.js
diff options
context:
space:
mode:
authorElis Eriksson <spelis@spelis.li>2026-07-07 22:35:51 +0200
committerElis Eriksson <spelis@spelis.li>2026-07-07 22:35:51 +0200
commitcda6973714d3770a887df6f6ff451636919170bb (patch)
treec1113f257d9982bf6982a31fd63b251eeec421fd /assets/js/morph.js
parentbd65a742f81157b5c4c9fe399db65a0c1838f47d (diff)
downloadspelis-web-cda6973714d3770a887df6f6ff451636919170bb.tar
spelis-web-cda6973714d3770a887df6f6ff451636919170bb.tar.gz
spelis-web-cda6973714d3770a887df6f6ff451636919170bb.tar.bz2
spelis-web-cda6973714d3770a887df6f6ff451636919170bb.tar.lz
spelis-web-cda6973714d3770a887df6f6ff451636919170bb.tar.xz
spelis-web-cda6973714d3770a887df6f6ff451636919170bb.tar.zst
spelis-web-cda6973714d3770a887df6f6ff451636919170bb.zip
more aesthetic changes + code formatting
Diffstat (limited to 'assets/js/morph.js')
-rw-r--r--assets/js/morph.js54
1 files changed, 27 insertions, 27 deletions
diff --git a/assets/js/morph.js b/assets/js/morph.js
index 728ff1f..aea6dff 100644
--- a/assets/js/morph.js
+++ b/assets/js/morph.js
@@ -1,43 +1,43 @@
const CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@._-";
function morph(element, target) {
- clearInterval(element._timer);
+ clearInterval(element._timer);
- const start = element.textContent;
- const length = Math.max(start.length, target.length);
+ const start = element.textContent;
+ const length = Math.max(start.length, target.length);
- let progress = 0;
+ let progress = 0;
- element._timer = setInterval(() => {
- progress += 0.05;
+ element._timer = setInterval(() => {
+ progress += 0.05;
- const currentLength = Math.round(
- start.length + (target.length - start.length) * progress
- );
+ const currentLength = Math.round(
+ start.length + (target.length - start.length) * progress
+ );
- let output = "";
+ let output = "";
- for (let i = 0; i < currentLength; i++) {
- if (progress > i / currentLength + 0.2 && target[i]) {
- output += target[i];
- } else {
- output += CHARS[Math.floor(Math.random() * CHARS.length)];
- }
- }
+ for (let i = 0; i < currentLength; i++) {
+ if (progress > i / currentLength + 0.2 && target[i]) {
+ output += target[i];
+ } else {
+ output += CHARS[Math.floor(Math.random() * CHARS.length)];
+ }
+ }
- element.textContent = output;
+ element.textContent = output;
- if (progress >= 1) {
- clearInterval(element._timer);
- element.textContent = target;
- }
- }, 15);
+ if (progress >= 1) {
+ clearInterval(element._timer);
+ element.textContent = target;
+ }
+ }, 15);
}
for (const link of document.querySelectorAll(".morph")) {
- const original = link.textContent;
- const alternate = link.dataset.alt;
+ const original = link.textContent;
+ const alternate = link.dataset.alt;
- link.addEventListener("mouseenter", () => morph(link, alternate));
- link.addEventListener("mouseleave", () => morph(link, original));
+ link.addEventListener("mouseenter", () => morph(link, alternate));
+ link.addEventListener("mouseleave", () => morph(link, original));
}