Re: [csswg-drafts] [cssom-view-1] Provide onAnimationEnd callback in scrollIntoView options (#3744)

I am so glad with the solution that the working group came up with. It is so much more robust than I was expecting and it is much better than all the example solutions posted in this issue.

This ticket can be closed now, the core of the issue has been resolved with the new `scrollend` event.

---

@alex-bacart thankyou for your code example. I would also include a check to see if the event exists.

This example will only use smooth animated scroll if the browser supports `scrollend`. Otherwise it will use a non-animated scroll to reach the element.

```js
function scrollIntoViewAndWait(element) {
    return new Promise(resolve => {
        if ('onscrollend' in window) {
            document.addEventListener('scrollend', resolve, { once: true });

            element.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
        } else {
            element.scrollIntoView({ block: 'center', inline: 'center' });
            resolve()
        }
    });
}
```

-- 
GitHub Notification of comment by Dan503
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/3744#issuecomment-1806939380 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Saturday, 11 November 2023 23:06:16 UTC