-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compile all animation functions into one file
- Loading branch information
1 parent
3c8845f
commit 243526c
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |