Created
April 18, 2015 07:57
-
-
Save tennisonchan/8b76a27f1db84571422e to your computer and use it in GitHub Desktop.
Detect user scroll position on page
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
var timeout20 = null; | |
var timeout50 = null; | |
onscroll = function(e){ | |
var scrollPosition = window.scrollY / (window.document.body.scrollHeight - window.innerHeight); | |
if(0.2 < scrollPosition && scrollPosition < 0.5){ | |
clearTimeout(timeout20); | |
timeout20 = setTimeout(function(){ | |
console.log('20%'); | |
}, 500); | |
} | |
if(0.5 < scrollPosition && scrollPosition < 1){ | |
clearTimeout(timeout50); | |
timeout50 = setTimeout(function(){ | |
console.log('50%'); | |
}, 500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment