From 1fc25997a7d4b3cf80dbc09a3f48afd031ba5d0e Mon Sep 17 00:00:00 2001 From: Jan Palma Date: Fri, 27 Feb 2026 17:59:06 +0100 Subject: Init --- assets/js/transitions.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 assets/js/transitions.js (limited to 'assets/js/transitions.js') diff --git a/assets/js/transitions.js b/assets/js/transitions.js new file mode 100644 index 0000000..e902a40 --- /dev/null +++ b/assets/js/transitions.js @@ -0,0 +1,53 @@ +const displacement = document.getElementById("displacement"); +const noise = document.getElementById("noise"); + + +var nextFunc = () => {} +function transitionOut(callback) { + document.body.style.filter = "url(#transition)" + const src = new Number(displacement.getAttribute("scale")); + noise.setAttribute("seed",Math.random() * 1000) + if (src < 100) { + displacement.setAttribute("scale", src + 20 + src); + nextFunc = () => transitionOut(callback) + requestAnimationFrame(nextFunc) + } else { + setTimeout(() =>{ + document.body.style.filter = "" + },1000); + callback() + } +} + +function transitionIn() { + document.body.style.filter = "url(#transition)" + const src = new Number(displacement.getAttribute("scale")); + noise.setAttribute("seed",Math.random() * 1000) + if (src > 0) { + displacement.setAttribute("scale", src - 1 - (Math.max(src,1)/4)); + nextFunc = () => transitionIn(); + requestAnimationFrame(nextFunc) + } else { + displacement.setAttribute("scale", 0); + document.body.style.filter = "" + } +} + +if (noise && displacement) { + displacement.setAttribute("scale", 200); + transitionIn() + const links = document.querySelectorAll("a"); + links.forEach(l => { + if (l.href.startsWith(location.origin)) { + l.addEventListener("click", (e)=>{ + e.preventDefault() + displacement.setAttribute("scale", 0); + transitionOut(() => { + location.href = l.href + }); + }) + } + }) +} else { + console.log("Can't do transitions!!") +} \ No newline at end of file -- cgit v1.3-7-ge9ab