How do I determine scrollHeight of a division use css overflow:auto?
I've tried:
$('test').scrollHeight(); $('test').height(); but that just returns the size of the div not all the content
Ultimately, I'm trying to create a chat and always have the scroll bar to the current message on the screen.
So I was thinking something like the following:
var test = $('test').height(); $('test').scrollTop(test);
Thank you,
Brian
We'll need to resize the Main. js component and make it as big as the scroll height of the window. To do so, we need to read scrollHeight property. import React, { useEffect, useState } from 'react'; const Main = () => { const [height, setHeight] = useState(0); useEffect( () => { setHeight(document.
scrollHeight value is equal to the minimum height the element would require in order to fit all the content in the viewport without using a vertical scrollbar. The height is measured in the same way as clientHeight: it includes the element's padding, but not its border, margin or horizontal scrollbar.
scrollHeight - element. clientHeight; // example element. scrollTop = maxScrollPosition; That should do what you need.
The scrollHeight property returns the height of an element including padding, but excluding borders, scrollbars, or margins.
Correct ways in jQuery are -
$('#test').prop('scrollHeight')
OR$('#test')[0].scrollHeight
OR$('#test').get(0).scrollHeight
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With