Detect when Scrollbar is not at the bottom of the page

Asked

Viewed 58 times

0

I am creating a Chat without refresh that displays your results in reverse order leaving the current ones at the bottom and the old ones at the top.

I already have the effect of moving the page to the end when a new comment is posted, however I need for this purpose when the user is moving the Scrollbar up.

My idea was to calculate the div height difference and scrolltop position, however the properties below does not take the total div size.

Js properties used:

  element.height()
  element.innerHeight()
  element.outerHeight()

Just for the record, my div has a 100% height and an auto overflow, I put an Hide overflow on the body too, I’ve changed these properties but still didn’t get the real value of the div.

Can anyone suggest any alternative to this case? I thank you all for your attention

  • What are you putting in element?

  • Hello, I am standard element by class using jquery or pure javascript. I get the height value, however it is limited to the current size of the screen, I can even say that the size is the starting rendering in the browser, after the div expands I can’t get that value anymore.

  • Puts everything inside a span with display: inine-block and take the height span, like: <div><span style="display: inine-block"> CONTEÚDO </span></div>

  • Hello, thanks for the tip, I did the process using spam and only manage to get the value that the browser renders from start according to the screen, I use a height of 100% in the element that receives the messages. I changed my logic and get a cool result, I put a button to enable and disable the Auto Scroll, then Using a bind with the scroll event I can add scrollTop + innerheight and compare with a scrollHeight inside an if. The if result is always positive when it reaches the end of the scrollbar. Funny that out of the if I don’t get the real height value.

  • Another detail is that I used jquery ready and window.load and also could not get the total size of div.

  • Another way is to make a $.each on div and add up the height of the child elements.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.