Jake, yes, I've a scrolling div and it loads 50 messages when the page loads. If the user wants to see older messages, I need to pull the older messages; which need to load at the top of existing stack of message in set of 50 messages.
However, this should happen when the user scrolls to the top (scrollbar hits the top of the scrollable div). The code I pasted accomplishes this. I could simply make an axios call to the server and get paginated results.
What I'm planning to do is make the axios call right before hitting the top of the div; say when the scrollbar is 300px down the top of the scrollable div.
I've seen 'Infinite-Scroll' plugin does this; but it does not support scrollbar hitting the top. It only makes server calls when the user is scrolling down and the scrollbar is 'x pixels (offset)' away from hitting the bottom of the scrollable div.
Perhaps 'if' isn't the right thing to do. I'm wondering what would be the way to trigger an event so that I can make axios call, get the results and append them at the top.
PS: Thank you for your response. I really appreciate the help you offer to jQuery newbies like me.