Typography · 03 of 33

Noise Jitter

Letters twitch with small random offsets on every frame, like a shaky signal. Uses requestAnimationFrame and translate, so it stays smooth and never triggers layout.

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<p class="jitter-headline" id="jitterHeadline"></p>

CSS

.jitter-headline {
  display: flex;
  justify-content: center;
  font-size: 3.5rem;
  font-weight: 600;
}

.jitter-char {
  display: inline-block;
  will-change: transform;
}

JavaScript

var headline = document.getElementById('jitterHeadline');
var text = 'Noise Jitter';
var JITTER = 5;   // max px displacement
var SPEED = 0.06;

headline.innerHTML = text.split('').map(function (c) {
  return '<span class="jitter-char">' + (c === ' ' ? '&nbsp;' : c) + '</span>';
}).join('');
var chars = headline.querySelectorAll('.jitter-char');
var seeds = Array.from(chars, function () { return Math.random() * 1000; });

// fract() of a sine hash — cheap 1D pseudo-noise
function noise1D(x) {
  var v = Math.sin(x * 12.9898) * 43758.5453;
  return v - Math.floor(v);
}

var phase = 0;
function tick() {
  phase += SPEED;
  chars.forEach(function (el, i) {
    var tx = (noise1D(seeds[i] + phase) - 0.5) * 2 * JITTER;
    var ty = (noise1D(seeds[i] + 100 + phase) - 0.5) * 2 * JITTER;
    el.style.transform = 'translate(' + tx + 'px, ' + ty + 'px)';
  });
  requestAnimationFrame(tick);
}
requestAnimationFrame(tick);