You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using window.onscroll = function(){ } you can execute code as the user scrolls your page.
The code below will track the height of the page using document.documentElement.offsetHeight and compare it to the height scrolled with document.documentElement.scrollTop + the height of the window window.innerHeight.
Then using if (offset >= (height * 0.9)) you can execute code when the amount scrolled + height of window is equal to 90% of the height of the page (i.e. the user has almost reached the bottom).
I haven't got it working perfectly at this stage - The tricky part is making sure the code will only be executed once when it reaches 90% - so comments/corrections welcome.
The text was updated successfully, but these errors were encountered:
I think the intersectionObserver also allows you to do this but in an asynchronous way which is better for performance (not 100% sure on this). You also don't have to do any calculations :)
I found it relatively easy to get working. However, its not fully supported yet. For anyone who's interested I found the following links helpful:
Using
window.onscroll = function(){ }
you can execute code as the user scrolls your page.The code below will track the height of the page using
document.documentElement.offsetHeight
and compare it to the height scrolled withdocument.documentElement.scrollTop
+ the height of the windowwindow.innerHeight
.Then using
if (offset >= (height * 0.9))
you can execute code when the amount scrolled + height of window is equal to 90% of the height of the page (i.e. the user has almost reached the bottom).I haven't got it working perfectly at this stage - The tricky part is making sure the code will only be executed once when it reaches 90% - so comments/corrections welcome.
The text was updated successfully, but these errors were encountered: