Skip to content

Instantly share code, notes, and snippets.

@jacobovidal
Created February 7, 2018 09:55
Show Gist options
  • Save jacobovidal/a796696f6e84ea25987afdd00452961e to your computer and use it in GitHub Desktop.
Save jacobovidal/a796696f6e84ea25987afdd00452961e to your computer and use it in GitHub Desktop.
Scroll tracking trigger to check if page height is bigger than the double of your viewport (Useful for Google Tag Manager)
// If using with GTM, anonymize the function name
function isScrollable() {
function getDocumentHeight() {
return Math.max(document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);
}
function getViewPortHeight() {
return Math.max(document.documentElement.clientHeight, window.innerHeight || 0) * 2;
}
if (getViewPortHeight() < getDocumentHeight()) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment