Skip to content

Commit

Permalink
compile all animation functions into one file
Browse files Browse the repository at this point in the history
  • Loading branch information
cwangsanata committed Sep 27, 2023
1 parent 3c8845f commit 243526c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions scripts/animations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Blob mouse follow animation effect
// Credit: https://codepen.io/Hyperplexed/pen/KKBjvbG
function blobAnimation() {
const blob = document.getElementById("blob");

window.onpointermove = event => {
const { clientX, clientY } = event;

blob.animate({
left: `${clientX}px`,
top: `${clientY}px`
}, { duration: 10000, fill: "forwards" });
}
}

// Typing text effect
function displayText() {
const textElement = document.getElementById('name');
const textToDisplay = "Chris Wangsanata";
let charIndex = 0;
const interval = setInterval(() => {
if (charIndex < textToDisplay.length) {
textElement.textContent += textToDisplay[charIndex];
charIndex++;
} else {
clearInterval(interval);
}
}, 75);
}

// Blinking cursor effect
function blinkCursor() {
setInterval(() => {
const cursor = document.getElementById("cursor");
cursor.style.opacity = cursor.style.opacity == 0 ? 1 : 0;
}, 500);
}

window.onload = () => {
displayText();
blinkCursor();
blobAnimation();
}

0 comments on commit 243526c

Please sign in to comment.