How to scroll to the top of the page with jQuery? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to scroll to the top of the page with jQuery?

Damian99Damian99 USAPosts: 116Member

I need to setup a user click action to scroll smoothly to the top of the page. Can someone please show a working code?

Tagged:

Comments

  • DavidMDavidM USAPosts: 342Member
    edited January 2014

    window.scrollTo(x-coord, y-coord);

    Parameters
    * x-coordis the pixel along the horizontal axis.
    * y-coord is the pixel along the vertical axis.

    For smooth scrolling,

    $("a[href='#top']").click(function() {
          $("html, body").animate({ scrollTop: 0 }, "slow");
          return false;
        });
Sign In or Register to comment.