Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 837
rusly Avatar asked Jan 18 '13 09:01

rusly


1 Answers

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.

like image 90
Rory McCrossan Avatar answered Sep 22 '22 15:09

Rory McCrossan