Home > Software engineering >  How to know `scrollIntoView` will do nothing?
How to know `scrollIntoView` will do nothing?

Time:08-15

Assume we want to call these 2 function in this specific order:

  1. scrollIntoView
  2. an user-defined function foo to be called after scrollIntoView finishes (possible scrolling)

Assume we have added an event 'scroll' callback to call foo. Now, the problem is that if the target DOM element is already in view, scrollIntoView will not scroll. In that case, event 'scroll' won't occur.

How do we have foo called, whenever the asynchronous function scrollIntoView finishes scrolling or doesn't need to scroll at all?

In other words, how do we know function scrollIntoView will visually do nothing?

This question is similar to How to know scroll to element is done in Javascript?.

CodePudding user response:

Check if element is in view https://stackoverflow.com/a/125106/19617075 and perform scrollIntoView or foo based on that.

  • Related