Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How scroll end page with vue js

How do I scroll to the bottom of the page?

scroll(){
    let container = this.$el.querySelector('#scrollingChat')
    container.scrollTop = container.scrollHeight
}

I'm doing this, and always calling my api answers, but it does not go to the bottom of the page

like image 994
Rafael Augusto Avatar asked Dec 14 '22 16:12

Rafael Augusto


2 Answers

window.scrollTo(0, document.body.scrollHeight || document.documentElement.scrollHeight);

This is will instantly scroll to the bottom of any page.

like image 146
James Harrington Avatar answered Dec 18 '22 06:12

James Harrington


If you create an anchor in your page like so:

<div id="top"></div>

you can use:

let elmnt = document.getElementById('top');
elmnt.scrollIntoView(false);

This page explains what the different alignment parameters do for scrollIntoView:

true - scrolls to top of element

false - scrolls to bottom of element

default it true

https://www.w3schools.com/jsref/met_element_scrollintoview.asp

like image 42
a_lovelace Avatar answered Dec 18 '22 07:12

a_lovelace