rusly rusly - 2 months ago 9
Javascript Question

Detect 30% from browser window bottom using scrollTop()

My code can detect browser window bottom like below and then run

last_msg_funtion();
:

$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
last_msg_funtion();
}
});


My problem is user need to scroll down until bottom(footer) then
last_msg_funtion();
will run but i want adjust the detection maybe around 30% from bottom

See image below :
enter image description here

My Site : Click Here

Full Code : Click Here

Answer

Try this:

$(window).scroll(function(){
    if ($(window).scrollTop() == ($(document).height() * 0.7) - $(window).height()){
       last_msg_funtion();
    }
}); 

Note the * 0.7 will mean that the function will fire when the scroll is 70% of the way down the page - ie. 30% from the bottom.