summaryrefslogtreecommitdiffstats
path: root/assets/js/hero-glitch.js
blob: 94ba4a00219b71d1253455345c78c62a269cafd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(function () {
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;

  function attachGlitch(el) {
    function glitch() {
      el.classList.add('is-glitching');
      setTimeout(function () { el.classList.remove('is-glitching'); }, 500);
      setTimeout(glitch, 4000 + Math.random() * 7000);
    }
    setTimeout(glitch, 3500);
  }

  document.querySelectorAll('.hero-name, .section-title').forEach(attachGlitch);
})();