Fix animation

This commit is contained in:
tree🌴 2023-02-16 12:58:21 +01:00
parent d8a3cd1063
commit 2c3abc1ece

View file

@ -21,12 +21,15 @@ export function animateText (ev) {
const orig = ev.target.getAttribute('data-text') const orig = ev.target.getAttribute('data-text')
const steps = orig.length const steps = orig.length
const random = rand(orig.length) const genRand = (pos = 0, len = null) => orig.substring(pos, len).split(' ').map(x => rand(x.length)).join(' ')
const random = genRand(0, orig.length)
ev.target.innerHTML = random ev.target.innerHTML = random
for (let i = 0; i <= steps; i++) { for (let i = 0; i <= steps; i++) {
setTimeout(() => { setTimeout(() => {
ev.target.innerHTML = orig.substring(0, i) + rand(orig.length - i) ev.target.innerHTML = orig.substring(0, i) + genRand(i, orig.length)
console.log(ev.target.innerHTML)
if (i === steps) { if (i === steps) {
ev.target.setAttribute('data-animate', "0") ev.target.setAttribute('data-animate', "0")