From the course: Ajax with PHP: Add Dynamic Content to Websites

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Trigger Ajax on scroll

Trigger Ajax on scroll

From the course: Ajax with PHP: Add Dynamic Content to Websites

Start my 1-month free trial

Trigger Ajax on scroll

- [Instructor] In the last movie, we got our LoadMore button working correctly. So it can retrieve pages of items and append them to a div on the current page correctly. Now, we're ready to add the infinite scrolling part. We just need to be able to trigger that same Ajax function, LoadMore. We need to do it whenever a user scrolls to the bottom of the current content. We aren't going to be able to do it all in one step exactly. What we first need to do, is we need to bind a function to our onscroll event. The way we do that is with window.onscroll all lowercase equals to, we're going to make an anonymous function here and inside there we're going to call scrollReaction. All right so anything we want to do with scroll is going to be handled by scrollReaction function. It's a function that I'm going to write and every time that the window scrolls, this function will be called, every time. Not just when we get to the bottom of the content, every single time we do any scrolling, this…

Contents