I want a popup to be displayed when user reaches a certain document height. For instance when reader approaches ~end of a post a popup can be triggered asking his/her input (comment whether liked post or not)
I tried fetching/passing document height via:
function doch() {
var currentscrollpos;
if (currentscrollpos > 1500) {
//trigger popup
alert(currentscrollpos);
}
setInterval(function() {
currentscrollpos = $(document).scrollTop();
return currentscrollpos;
}, 3e3);
}
in html function can be simply triggered via doch();
The problem is, that the value of currentscrollpos can’t be passed from setInterval function to if loop?
Why use setInterval if you can bind to when a user scrolls down the page?
http://jsfiddle.net/rUbwq/2/