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!
}
}
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!
}
}
Share
Improve this question
edited Jan 31, 2019 at 15:40
Amirhossein Mehrvarzi
19k7 gold badges50 silver badges73 bronze badges
asked Apr 6, 2017 at 22:08
edmamertoedmamerto
8,15512 gold badges53 silver badges81 bronze badges
1
- Note, that there's a new way of creating references to a dom element: reactjs/docs/refs-and-the-dom.html – fraxture Commented Dec 26, 2017 at 16:24
1 Answer
Reset to default 4Since 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744222958a4563872.html
评论列表(0条)