Skip to content
Advertisement

How can I convert scrollIntoView with smooth animation to a Promise?

I have to scrollIntoView a particular element smoothly and then do something.

Example

JavaScript

I know that it can’t be done this way as native scrollIntoView doesn’t return a Promise. But, how do I achieve something like this?

I’m using Angular 7 BTW. So if there are any directives that could help me achieve this, it would be great.

Advertisement

Answer

You can work with prototypes, I think this could be a solution to your problem without download any npm packages

JavaScript

I’ve created an example. I know it’s not an angular application, but it’s a good starting point. You just need to implement it (If you’re using typescript you have to create an interface which extends Element with the new function).

Advertisement