To scroll to the bottom of the page using TypeScript, you can use the scrollTo()
method which is built-in in the window
object. Here's how you can do it:
index.ts78 chars5 lines
The scrollTo()
method takes an object as an argument with two properties:
top
: The Y coordinate to scroll to. We set it to the scrollHeight
of the document.body
element to scroll to the bottom of the page.behavior
: The scrolling behavior. We set it to 'smooth'
to get a smooth scrolling animation, but you can also set it to 'auto'
to get an instant scrolling behavior.With this code, when you call window.scrollTo()
it will automatically scroll to the bottom of the page with a smooth animation.
gistlibby LogSnag