Skip to content

Instantly share code, notes, and snippets.

@jaredreich
Created February 27, 2018 20:51
Show Gist options
  • Save jaredreich/3313353ec5b1c7932aebadd8fd121f70 to your computer and use it in GitHub Desktop.
Save jaredreich/3313353ec5b1c7932aebadd8fd121f70 to your computer and use it in GitHub Desktop.
iframe scroll to bottom detection (cross browser, including mobile safari)
window.addEventListener('scroll', handleScroll);
window.addEventListener('message', handleMessage);
handleMessage = (event) => {
if (event.data === 'scrolledToBottom') handleScrolledToBottom();
}
handleScroll = () => {
if ((window.innerHeight + window.pageYOffset) >= window.document.body.scrollHeight) {
this.handleScrolledToBottom();
}
}
handleScrolledToBottom = () => {
// do something
}
const handleScroll = (event) => {
if ((window.innerHeight + window.pageYOffset) >= document.body.scrollHeight) {
window.parent.postMessage('scrolledToBottom', '*')
}
}
window.addEventListener('scroll', handleScroll);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment