magic-akari / seamless-scroll-polyfill

Scroll Behavior polyfill
https://www.npmjs.com/package/seamless-scroll-polyfill
MIT License
159 stars 12 forks source link

Detect after scroll finish #130

Closed gentcarbmanager closed 2 years ago

gentcarbmanager commented 2 years ago

Hello, thanks for this amazing package.

Is there any way to detect when scroll finished ?

elementScrollIntoView('#element', {
 behavior: 'smooth',
 block: 'center',
}).then(() => {
 // Do something
});
magic-akari commented 2 years ago

Hi, The scrollIntoView should return undefined according the spec.


When a user agent is to perform a smooth scroll of a scrolling box box to position, it must update the scroll position of box in a user-agent-defined fashion over a user-agent-defined amount of time. When the scroll is completed, the scroll position of box must be position. The scroll can also be aborted, either by an algorithm or by the user.

You can pass in a third parameter to set the duration. However, it should be noted that after such a time, the page may not be in the destination position, as scrolling can be aborted by the user.