-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglitchText.min.js
1 lines (1 loc) · 937 Bytes
/
glitchText.min.js
1
const glitchText=(()=>{const o={};const t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";const e=(t,n)=>Math.floor(Math.random()*(n-t+1)+t);const c=()=>t[e(0,t.length-1)];function n(t,n={}){const e=Symbol();o[e]={t:t,text:n.text||t.textContent,speed:n.speed||10,o:n.o||10};return e}function r(t){const n=o[t];if(n){n.t.textContent=n.text;delete o[t]}}function s(t){return o[t]}function i(t,n,e=false){const c=o[t];if(!c)return;if(!e)c.i=c.text.length;c.u=n}function f(t,n){return t.split("").map(t=>{if(e(1,n)===1)return c();else return t}).join("")}(function u(){requestAnimationFrame(u);for(const t of Object.getOwnPropertySymbols(o)){const n=o[t];const e=n.t;if(!n.l){if(!n.i){if(n.u){n.text+=n.u[0];n.u=n.u.slice(1)}else n.u=null}e.textContent=f(n.text,n.o);n.l=n.speed}else n.l--;if(n.i){n.i--;n.text=n.text.slice(0,-1);e.textContent=e.textContent.slice(0,-1)}}})();return{register:n,unregister:r,get:s,set:i}})();