Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine scrollHeight?

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

like image 898
Brian Avatar asked Sep 11 '11 22:09

Brian


People also ask

How do you set scrollHeight in react?

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.

How is scrollHeight calculated?

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.

How do I get scrollHeight in CSS?

scrollHeight - element. clientHeight; // example element. scrollTop = maxScrollPosition; That should do what you need.

What is scrollHeight in JS?

The scrollHeight property returns the height of an element including padding, but excluding borders, scrollbars, or margins.


1 Answers

Correct ways in jQuery are -

  • $('#test').prop('scrollHeight') OR
  • $('#test')[0].scrollHeight OR
  • $('#test').get(0).scrollHeight
like image 168
Anmol Saraf Avatar answered Oct 06 '22 00:10

Anmol Saraf