user6070602
user6070602

Reputation:

Page scrolling error on button click jQuery

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!

Upvotes: 1

Views: 629

Answers (1)

Inpyo Jeon
Inpyo Jeon

Reputation: 220

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.

Upvotes: 2

Related Questions