Create Scroll-Triggered Letter Animations – AniLet.js
It splits text into separate spans and applies staggered animations to create typewriter-style effects with visual flair.
1. For npm-based projects with bundlers like Webpack or Vite, install the package and import the built file:
# NPM $ npm install ani-let
import 'ani-let/dist/aniLet.min.js';
2. For projects without a build step, reference the library directly from a CDN:
<script src="https://cdn.jsdelivr.net/npm/ani-let/dist/aniLet.min.js"></script>
3. Or download the file and host it locally:
<script src="/path/to/aniLet.min.js"></script>
4. Add the aniLet base class and one animation modifier class to any text element. The library automatically initializes on page load and watches for scroll events.
The animation triggers when 90% of the element enters the viewport, animating each letter sequentially with a default 50ms delay between characters.
<div class="aniLet aniLet__fadeIn">Text Here</div>
5. The library currently provides 11 animation styles through modifier classes:
6. Tweak the animation’s timing with these data- attributes:
data-delay: Sets the delay between each letter’s animation in milliseconds. The default is 50.data-duration: Sets the total duration for the entire text animation in milliseconds. The default is 1000.<div class="aniLet aniLet__zoomIn" data-delay="80" data-duration="800"> Custom Timing </div>
AniLet.js works through a three-stage process: text splitting, viewport monitoring, and frame-based animation rendering.
During initialization, the library queries all elements with the aniLet class and wraps each character in a span element with inline-block display and zero opacity. Spaces get converted to non-breaking spaces to preserve layout. This text splitting happens only once per element, tracked via a data attribute flag.
The viewport detection system uses scroll event listeners combined with getBoundingClientRect() calculations. An element triggers its animation when its top edge crosses 90% of the viewport height and its bottom edge remains above the viewport top. Once triggered, the scroll listener removes itself to prevent re-triggering.
The animation engine uses requestAnimationFrame for smooth rendering. Each letter gets its own animation function that calculates progress based on performance.now() timestamps. Progress values feed into cubic easing functions (specifically 1 - Math.pow(1 - progress, 3)) that create natural acceleration. Different animation types apply these eased values to CSS transform properties. The bounce animation implements a multi-stage timeline with different scale and opacity values at specific progress thresholds.
The library avoids CSS transitions entirely, instead calculating and applying transforms on every frame. This approach gives precise control over timing and easing curves while maintaining compatibility across browsers.
Q: What happens if I apply multiple animation classes to the same element?
A: The library checks classes in a fixed order defined in its internal map object. Whichever animation class appears first in that map will be used, regardless of HTML class order. Only one animation type can be active per element.
Q: Does this work with dynamically inserted content?
A: No. The library only initializes once on DOM ready. Text added after page load won’t be processed.
Q: How does this affect SEO and screen readers?
A: The text content remains in the DOM and accessible to crawlers and screen readers since the library only wraps characters in spans without changing the text itself.
The post Create Scroll-Triggered Letter Animations – AniLet.js appeared first on CSS Script.
AvalynxAutocomplete is a lightweight Bootstrap autocomplete component that converts text inputs into searchable, keyboard-navigable dropdown…
LANSING, MI (WOWO) Michigan officials are calling for new legislation and increased security funding following…
LANSING, MI (WOWO) Michigan officials are calling for new legislation and increased security funding following…
LANSING, MI (WOWO) Michigan officials are calling for new legislation and increased security funding following…
LANSING, MI (WOWO) Michigan officials are calling for new legislation and increased security funding following…
MACOMB COUNTY, MI. (WOWO) A 40-year-old man convicted in a petition signature fraud scheme tied…
This website uses cookies.