diff options
Diffstat (limited to 'assets/js/glitch.js')
| -rw-r--r-- | assets/js/glitch.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/assets/js/glitch.js b/assets/js/glitch.js new file mode 100644 index 0000000..85f8a00 --- /dev/null +++ b/assets/js/glitch.js @@ -0,0 +1,30 @@ +/** + * glitch.js + * Random glitch effect on .hero-name every 4-11 seconds + */ + +export function initGlitch() { + 'use strict'; + + const heroName = document.querySelector('.hero-name'); + if (!heroName) return; + + if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return; + + function triggerGlitch() { + heroName.classList.add('is-glitching'); + setTimeout(() => { + heroName.classList.remove('is-glitching'); + }, 450); + } + + function scheduleNextGlitch() { + const delay = Math.random() * 7000 + 4000; // 4-11 seconds + setTimeout(() => { + triggerGlitch(); + scheduleNextGlitch(); + }, delay); + } + + scheduleNextGlitch(); +} |
