Scroll · 32 of 34
Velocity Skew
Text skews in proportion to how fast you scroll and snaps back when you stop. Scroll velocity is measured per frame and applied as skewX.
This one is driven by scroll position, so it reads best in context. See it on the scroll page.
<!-- Needs a scrollable page — the skew follows how fast you scroll -->
<section class="velocity-skew-section">
<h2 class="velocity-text">Scroll Fast!</h2>
</section>
.velocity-skew-section {
min-height: 35vh;
display: flex;
align-items: center;
justify-content: center;
}
.velocity-text {
font-size: 2.5rem;
color: #f0f0f5;
will-change: transform;
}
var text = document.querySelector('.velocity-text');
var MAX_SKEW = 20; // deg — cap for very fast scrolls
var SENSITIVITY = 0.8; // deg of skew per px of scroll per frame
var SMOOTH = 0.12; // lerp factor — springs back toward 0
var lastScrollY = window.scrollY;
var skew = 0;
function tick() {
var y = window.scrollY;
var velocity = y - lastScrollY;
lastScrollY = y;
var target = Math.max(-MAX_SKEW, Math.min(MAX_SKEW, velocity * SENSITIVITY));
skew += (target - skew) * SMOOTH;
text.style.transform =
'skewY(' + skew + 'deg) scaleY(' + (1 + Math.abs(skew) * 0.01) + ')';
requestAnimationFrame(tick);
}
requestAnimationFrame(tick);