When calling scrollIntoView, you can provide a settings object to customize the animation behavior and alignment.
| Key | Type | Default | Description |
|---|
time | number | 1000 | Duration of the animation in milliseconds. |
ease | function | (v) => 1 - Math.pow(1 - v, v / 2) | An easing function that receives a value from 0 to 1 and returns a value for the animation progress. |
align | object | { top: 0.5, left: 0.5 } | Alignment configuration for the target element within the scrollable container. |
validTarget | function | () => true | A predicate function (target, parentsScrolled) => boolean. If it returns false, the parent is skipped in the scroll chain. |
isScrollable | function | defaultIsScrollable | A predicate function (target, defaultIsScrollable) => boolean. Allows overriding the default check for whether an element is scrollable. |
{
time: 500,
ease: function(value) {
return Math.pow(value, 2) - value;
},
validTarget: function(target, parentsScrolled) {
// Example: Only scroll parents that don't have the class 'dontScroll'
return !target.matches('.dontScroll');
},
align: {
top: 0, // 0 (top) to 1 (bottom). Default 0.5 (center)
left: 0.5, // 0 (left) to 1 (right). Default 0.5 (center)
topOffset: 0, // Pixels to offset top alignment
leftOffset: 0 // Pixels to offset left alignment
},
isScrollable: function(target, defaultIsScrollable) {
// Example: Treat elements with class 'scrollable' as scrollable even if overflow is hidden
return defaultIsScrollable(target) || target.classList.contains('scrollable');
}
}