-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 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
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,57 @@ | ||
export function animate(animationName, animationDuration, fontSizeIncrease) { | ||
const container = document.querySelector('.container'); | ||
|
||
// Check if container exists | ||
if (!container) { | ||
console.error("Couldn't find container. Thrown by Cheugy"); | ||
return; | ||
} | ||
|
||
const elements = Array.from(container.querySelectorAll('h1, p')); | ||
const styleElement = document.createElement('style'); | ||
document.head.appendChild(styleElement); | ||
const stylesheet = styleElement.sheet; | ||
|
||
const keyframes = ` | ||
@keyframes ${animationName} { | ||
0%, 100% { | ||
font-size: calc(initial + 1em); | ||
} | ||
50% { | ||
font-size: ${fontSizeIncrease}em; | ||
} | ||
} | ||
`; | ||
|
||
// Insert the keyframes into the stylesheet | ||
stylesheet.insertRule(keyframes, stylesheet.cssRules.length); | ||
|
||
elements.forEach(element => { | ||
const words = element.textContent.split(' '); | ||
const randomIndex = Math.floor(Math.random() * words.length); | ||
const originalWord = words[randomIndex]; | ||
|
||
const animatedWord = ` | ||
<span | ||
class="text-element" | ||
style="animation: ${animationName} ${animationDuration}s cubic-bezier(0.68, -0.55, 0.27, 1.55) forwards;" | ||
>${originalWord}</span> | ||
`; | ||
|
||
words[randomIndex] = animatedWord; | ||
element.innerHTML = words.join(' '); | ||
|
||
const animatedElement = element.querySelector('.text-element'); | ||
|
||
// Check if animatedElement exists | ||
if (!animatedElement) { | ||
console.error("Couldn't find animated element. Thrown by Cheugy"); | ||
return; | ||
} | ||
|
||
animatedElement.addEventListener('animationend', () => { | ||
words[randomIndex] = originalWord; | ||
element.innerHTML = words.join(' '); | ||
}); | ||
}); | ||
} |
Binary file not shown.
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,5 @@ | ||
"Hello" | ||
function face() { | ||
var hello = 3 | ||
hello | ||
} |