scroll-into-view / scroll-into-view-if-needed

Element.scrollIntoView ponyfills for things like "if-needed" and "smooth"

Home Page:https://scroll-into-view.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scrolls both window and container

denkristoffer opened this issue Β· comments

Hi πŸ‘‹ Thanks for making this library!

I'm using it to scroll a list that has overflow-y: scroll. However, when scrolling to an element on the bottom of this list the window is scrolled to the bottom as well. Is there a way to avoid this or is it a bug?

Yes you can prevent it by using an undocumented 4th argument:

scrollIntoViewIfNeeded(
  activeNode,
  false,
  {
    duration: 150
  },
  activeNode
)

In the next major release we'll have 2 arguments instead of 5 (!) like now πŸ˜…

The 4th argument acts as a boundary. It works similar to the jquery $.closest api in that it recurses from your element and up the tree until it reaches the window.

Let me know if it works for you πŸ˜„

Oh I see now, sorry for not digging further into the code. It works perfectly πŸ‘ Thanks!

No worries at all πŸ˜„ This should've been documented tbh (and it will be soon) πŸ™‚