1

I am trying to implement an infinite scroll in my chat widget. I have a ref setup for chat body's container like this:

const containerNode = ReactDOM.findDOMNode(this.refs.container)

I also already setup an event listener that handle's the scroll:

containerNode.addEventListener('scroll', this.handleScroll);

I am now trying to find out how to implement the use case where before i can scroll up, it would make an ajax call.

handleScroll() {
    console.log("make an ajax call before it scrolls all the way up")
    if (some_conditon){
      //then load more!
    }
  }

enter image description here

1

1 Answer 1

4

Since you are scrolling up to the top all you need to do is look at the scroll top of your container.

const offset = 100 // 100 px before the request
if (containerNode.scrollTop < offset) {
    // request more here
}

SAMPLE FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.