Howdy, Stranger!

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


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

Damian99Damian99 USAMember Posts: 116

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



  • DavidMDavidM USAMember Posts: 342
    edited January 2014

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

    * x-coord is 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.