1

I want to scroll page to second section on a button click. I am using following jquery

$('.home_scroll_btn a').on('click', function(){
        var scrollPosition = $('#intro-home').offset().top;
        $('html, body').animate({
            scrollTop:scrollPosition
        });
    });

The problem is when i click the button the page first scroll to top and then scroll to particular section.

Thanks in advance!

3
  • Add your html to the question. Commented Mar 25, 2016 at 7:06
  • Your code seems to work perfectly. Just use javascript:void(0) as href. Check this FIDDLE Commented Mar 25, 2016 at 7:17
  • its working now thanx Commented Mar 25, 2016 at 7:26

1 Answer 1

2

If .home_scroll_btn a has href="#" or something like that, it will scroll up to the top. If it does have one, add e.preventDefault() or return false on the function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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