Typography · 02 of 33

Wave Distort

Each character bobs on a sine wave with a phase offset from its neighbour, producing a rolling distortion. Pure CSS transforms driven by a tiny per-letter delay.

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<p class="wave-headline" id="waveHeadline"></p>

CSS

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

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

JavaScript

var headline = document.getElementById('waveHeadline');
var text = 'Wave Distortion';
var AMPLITUDE = 20;  // px
var FREQUENCY = 5;   // full sine cycles across the text

headline.innerHTML = text.split('').map(function (c) {
  return '<span class="wave-char">' + (c === ' ' ? '&nbsp;' : c) + '</span>';
}).join('');
var chars = headline.querySelectorAll('.wave-char');

var phase = 0;
function tick() {
  phase += 0.035;
  chars.forEach(function (el, i) {
    var y = Math.sin((i / (chars.length - 1)) * Math.PI * 2 * FREQUENCY + phase) * AMPLITUDE;
    el.style.transform = 'translateY(' + y + 'px)';
  });
  requestAnimationFrame(tick);
}
requestAnimationFrame(tick);