admin管理员组

文章数量:1410730

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 :

My Site : Click Here

Full Code : Click Here

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 :

My Site : Click Here

Full Code : Click Here

Share Improve this question asked Jan 18, 2013 at 9:13 ruslyrusly 1,5226 gold badges29 silver badges62 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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.

Try these:

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

you have to use >= in if condition.

If you use == then last_msg_funtion() will call only when scroll is 70% on way.

If you use >= then last_msg_funtion() will call only when scroll is greater than 70% on way.

本文标签: javascriptDetect 30 from browser window bottom using scrollTop()Stack Overflow