Skip to content

Add scroll-promises examples#386

Merged
chrisdavidmills merged 7 commits into
mdn:mainfrom
chrisdavidmills:scroll-promises-examples
Jun 26, 2026
Merged

Add scroll-promises examples#386
chrisdavidmills merged 7 commits into
mdn:mainfrom
chrisdavidmills:scroll-promises-examples

Conversation

@chrisdavidmills

Copy link
Copy Markdown
Contributor

In Chrome 150 onwards, the standard Element and Window scroll methods now return promises. See https://chromestatus.com/feature/5082138340491264. This is particularly useful when a scroll operation is not instantaneous (e.g. you've got scroll-behavior: smooth; set on the scrolling container), and you want to programmatically react to the scroll operation finishing, for example, by updating the UI.

Affected methods are:

  • Element.scroll()
  • Element.scrollBy()
  • Element.scrollIntoView()
  • Element.scrollTo()
  • Window.scroll()
  • Window.scrollBy()
  • Window.scrollTo()

This PR adds a couple of demos that show each promise-returning scroll method in use. I could do these as live examples, but I decided not to, as I don't want to add a huge standalone live example to all seven pages, with all of them doing nearly the same thing. I'd rather provide a couple of code snippets on each page and then link to the full example.

@chrisdavidmills chrisdavidmills requested review from a team as code owners June 19, 2026 08:55
@chrisdavidmills chrisdavidmills requested a review from dipikabh June 19, 2026 08:55

@hamishwillee hamishwillee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty cool except that after pressing any of these buttons the bar fades and I can't get it back. I can still press the invisible buttons, but to make the bar reappear I need to refresh the page - not ideal

Image

Edit - this is using latest chrome on refresh, which is still 149

@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

@hamishwillee darnit, adding the usage of the interrupted property from the fulfillment value completely broke it in non-supporting browsers ;-)

To fix this up, I've added a feature detection function and used that to register different event handlers depending on whether the browser supports the promise-returning scroll functions.

I'm then intending to just add a note about the feature detection in the articles, but I thought I'd ask your opinion first.

I'd rather do it this way to avoid making the event handler explanation any more complicated in the articles.

@hamishwillee

Copy link
Copy Markdown

I think that makes sense.

@pepelsbey pepelsbey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you 🙂

Just a few suggestions for readmes and titles.

Comment thread scroll-promises/element-methods/index.html Outdated
Comment thread scroll-promises/window-methods/index.html Outdated
Comment thread README.md Outdated
chrisdavidmills and others added 4 commits June 26, 2026 13:45
Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
@chrisdavidmills chrisdavidmills merged commit a604b16 into mdn:main Jun 26, 2026
1 check passed
@chrisdavidmills chrisdavidmills deleted the scroll-promises-examples branch June 26, 2026 13:12
@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

Looks good! Thank you 🙂

Just a few suggestions for readmes and titles.

Super, ta!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants