Tilting Diamond Range Slider Effect
See the Pen Tilting Diamond Range Slider Effect.
Tech & Dependencies
Features
- ✓ Lerp Animation
- ✓ Kinetic Tilt
- ✓ Native Input
Browser Support
Core
This is a Tilting Diamond Range Slider Effect. It tracks user input through a hidden native range element, overlaying a custom graphical interface. Its primary function is to inject physical inertia into a standard digital control. The tooltip mimics mass, lagging behind rapid movements and tilting in the direction of travel.
Specs
- Weight: ~3 KB (Zero external dependencies for core logic).
- Performance: High. The
requestAnimationFrameloop strictly updates CSS variables. Transformations are GPU-accelerated (transform: translateX() rotate()). - Theming: Centralized via the
--color-primaryCSS variable. - Responsiveness: Fluid width. Scales perfectly across mobile and desktop interfaces.
- Graceful Degradation: [!] If JS fails, the native
<input type="range">remains fully functional but invisible. It is recommended to add a fallback class to reveal the native input if the JS bundle does not load.
Anatomy
- HTML (The Skeleton): Relies on a standard
<input type="range">for accessibility and mobile touch support. Custom visual layers (.slider-track,.slider-thumb,.slider-diamond) are absolute-positioned on top. - CSS (The Skin): Masks the native input (
opacity: 0) while keeping it clickable. Maps JS-calculated variables (--d,--tilt) directly to CSStransformrules. - JS (The Nervous System): A custom linear interpolation (
lerp) engine. It continuously calculates the distance between the user’s target value and the current visual value, broadcasting the state to the DOM.
Logic
The elegance lies in extracting the velocity from the interpolation gap.
const tilt = Math.min(6, target - current);
elDiamondSlider.style.setProperty("--tilt", tilt);
Instead of complex event listeners tracking mouse speed, the script simply compares the actual input value (target) against the visually rendered value (current). The larger the gap, the faster the slider is moving, which directly translates to a more extreme rotation angle (--tilt).
Feel
Tactile and elastic. Dragging the slider feels like pulling a physical object attached to a rubber band. The diamond tooltip springs out on hover, leans into the drag, and snaps smoothly into place when released. The visual feedback perfectly matches the physical intent.


