0

I have one page where the next page is fired when the user reaches the bottom of the page:

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

However, I want next page to be fired when the user reaches 50% of the page height or 200 px from the top.

0

2 Answers 2

3

It's basic math. Without it, jQuery ain't gonna help you at all:

$(window).scroll(function() {
  if (($(window).scrollTop() < 200) || ($(window).scrollTop() < $(document).height() / 2)) {
    next_funtion();
Sign up to request clarification or add additional context in comments.

1 Comment

I tried your code but its not working for me in all browser. see my window height varies from 3000-5000 px but document height of first page which is included in parent page is approx 800 px which start from about 600 px from the top in parent page.and every time i scroll there is one next function which ll call next page whose height is approx 500 px .its not working . i dont know where i am doing mistake when i open and run that page in browser it works but when i am including that page in parent page its not working . any idea where i am doing mistakes.
0

You can try this code for ScrollTop Function

$('html,body').animate({

      scrollTop: $('#'+id_name).offset()

    }, "fast");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.