Created
February 27, 2018 20:51
-
-
Save jaredreich/3313353ec5b1c7932aebadd8fd121f70 to your computer and use it in GitHub Desktop.
iframe scroll to bottom detection (cross browser, including mobile safari)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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