ESL Incremental Scroll New

ESL Incremental Scroll is a utility module that provides smooth, adaptive scrolling to elements with dynamic content support.

Unlike standard scrolling methods, incremental scroll recalculates the target position on every animation frame, making it ideal for pages with animations, transformations, or dynamically changing content. The scroll automatically adjusts to content changes during the animation, ensuring the element reaches the correct final position.

Key Features:

ESLIncrementalScroll public API

ESLIncrementalScroll.to

The main method to perform incremental scroll.

ESLIncrementalScroll.to($el: HTMLElement | null, options: ESLIncrementalScrollOptions = {}): Promise<void>

Parameters:

Returns: Promise<void> that resolves when scroll completes or rejects if aborted

Example:

const $target = document.querySelector('.target');

// Basic usage with default options
await ESLIncrementalScroll.to($target);

// With options
await ESLIncrementalScroll.to($target, {
  alignment: {
    y: alignToTop
  },
  offset: 30,
  timeout: 3000,
  stabilityThreshold: 300
});

// With AbortController
const controller = new AbortController();
ESLIncrementalScroll.to($target, {signal: controller.signal});
// Later: controller.abort();

ESLIncrementalScroll.defaults

You can configure global default options that will be applied to all scroll operations.

Getter returns a copy of the current default options. Setter - sets default options for incremental scroll. Only defined values will be applied.

Example:

import {ESLIncrementalScroll} from '@exadel/esl/modules/esl-incremental-scroll';

// Gets global defaults
const currentDefaults = ESLIncrementalScroll.defaults;

// Sets global defaults
ESLIncrementalScroll.defaults = {
  alignment: {
    y: alignToMiddle({})
  },
  offset: 20,
  stabilityThreshold: 300,
  timeout: 3000
};

// Now all scrolls will use these defaults
await ESLIncrementalScroll.to(element); // Will center vertically with 20px offset

Configuration Options

Important Notice: Values of alignment and offset always replace previous objects entirely (both in ESLIncrementalScroll.to() calls and when setting ESLIncrementalScroll.defaults). Provide both axes explicitly if you need to configure both.

Alignment Strategies

Alignment strategies determine how the element should be positioned relative to the viewport or scroll container.

Important: Alignment strategies are not included in the default export to keep your bundle size minimal and enable effective tree-shaking. You need to explicitly import only the strategies you actually use in your application.

Vertical Alignment

Horizontal Alignment

No Alignment

Example:

import {
  ESLIncrementalScroll,
  alignToTop,
  alignToMiddle,
  alignToCenter
} from '@exadel/esl/modules/esl-incremental-scroll';

// Align to top with offset
await ESLIncrementalScroll.to(element, {
  alignment: {
    y: alignToTop
  }
});

// Center both axes
await ESLIncrementalScroll.to(element, {
  alignment: {
    x: alignToCenter,
    y: alignToMiddle
  }
});