Description
scroll-into-view-if-needed is a small, dependency-free ponyfill for the Element.scrollIntoView API. It adds options that are not yet in the standard, including a scrollMode of if-needed, which scrolls an element only when it is not fully visible, and a boundary option, which limits scrolling to a chosen parent so that other ancestors stay where they are. The README says the core package is intentionally minimal. Smooth scrolling is ponyfilled only by an add-on package, smooth-scroll-into-view-if-needed, and the README notes that native smooth scrolling is enough when it works in your target browsers. Block and inline alignment accept start, center, end and nearest. You can pass a function as the behavior option to customize exactly how an element scrolls when smooth scrolling is not enough, for example with a custom transition. The site includes live examples of each option, including one that uses a popmotion transition. The README points out that the boundary option is non-standard and is not in any spec. The project links to a pull request in the CSS working group drafts that proposes the if-needed option for the standard API. You install it as a package and import the function to use in place of the built-in method.…
Highlights
- Ponyfill for scrollIntoView with if-needed scrolling
- Boundary option to limit which parents scroll
- Block and inline alignment options
- Custom behavior functions for transitions
- Dependency-free core package
Ratings & Reviews
No ratings yet
Be the first to rate Scroll Into View If Needed.
People also visit
Scroll Into View If Needed FAQ
What does this package do?
It provides scrollIntoView behavior that the standard does not yet offer, such as scrolling only when an element is not fully visible.
Does it depend on other packages?
The core package has no dependencies. Smooth scrolling needs the separate add-on package.
Do I need the add-on for smooth scrolling?
Only if native smooth scrolling does not work well in your target browsers, according to the README.
Is the boundary option standard?
No. The README says it is a non-standard feature that is not in any spec.
How do I use it?
Install the package and import its scrollIntoView function in place of the built-in method.
What are the best Scroll Into View If Needed alternatives?
Popular alternatives to Scroll Into View If Needed include Scroll-Btween and SSGOI. See all Scroll Into View If Needed alternatives
















