This utility library addresses the inconsistent behavior of the `Element.scrollLeft` property when an element's direction is set to Right-to-Left (RTL) across different browsers. It provides methods to detect the browser's specific `scrollLeft` implementation type (e.g., WebKit's 'default', Firefox/Opera's 'negative', IE/Edge's 'reverse') and then normalize `scrollLeft` values to a consistent, WebKit-like `0` (most left) to `100` (most right) range for both getting and setting. The current stable version is 0.2.1. Releases appear to be driven by bug fixes and feature enhancements, such as ESM support in v0.2.0. Its key differentiator is robust feature detection to abstract away browser quirks, enabling developers to work with a predictable `scrollLeft` API for RTL content, based on established patterns from jQuery plugins and Stack Overflow solutions. It explicitly handles Server-Side Rendering (SSR) environments by returning `indeterminate` or `NaN` for relevant functions, indicating non-browser execution.
npm install normalize-scroll-leftVerified import paths — ran on the pinned version, not inferred.
Demonstrates detecting scroll behavior, creating an RTL scrollable element, and using normalized functions to get and set its scroll position consistently across browsers.
Use ESM `import` statements (e.g., `import { name } from 'pkg';`) instead of CommonJS `require()` for newer versions. Ensure your build system is configured to handle ESM modules.Ensure `detectScrollType()` is called in a client-side context after the DOM is ready (e.g., within a `DOMContentLoaded` listener). For SSR, check for `typeof document !== 'undefined'` before invocation or account for the `'indeterminate'` return type.
Always pass the correct, explicitly known `direction` ('rtl' or 'ltr') corresponding to the element's computed style. Do not rely on the library to infer it.Implement client-side checks for these functions or handle `NaN` as a possible return value for `getNormalizedScrollLeft()` in universal applications. Avoid calling `setNormalizedScrollLeft()` in SSR contexts where DOM manipulation is not possible.
Wrap DOM-dependent calls in a client-side check, e.g., `if (typeof document !== 'undefined') { /* call function */ }`, or ensure these functions are only executed on the client-side.Ensure that `detectScrollType()` is called only after the DOM is ready, for instance, within a `DOMContentLoaded` event listener or at the end of the `<body>` in traditional scripts.
Verify that the `direction` argument (e.g., `'rtl'`) explicitly passed to the normalization functions accurately reflects the `getComputedStyle().direction` of the target `HTMLElement`.
No dependency data recorded yet.