Simple steps to return to the top of the effect _jquery

Source: Internet
Author: User

Share with you today on the page often appear in return to the top effect

Can omit a lot of code compared to the native Javascript,jquery implementation.

The next step is to post the code directly:

$ (function () {
    $ (window). Scroll (function () {//scroll--browser scroll bar scrolling triggers
        var wheight=$ (window). Height (); Gets the height of the browser visual window
        var wtop=$ (window). scrolltop ()///Get the scroll bar distance to the top
        if (wtop>=wheight)///When the scroll bar is more than one screen from the top height
           $ ("#btn"). Show ()///Return Top button display
        }
        else{
           $ ("#btn"). Hide ();//back to top button hide
        }
      );
      $ ("#btn"). Click (function () {
          $ ("Html,body"). Animate ({scrolltop:0},500);//page 500 milliseconds to return top
      });
 

OK, is not very simple, jquery directly provides us with the Animate method can quickly achieve return to the top of the animation effect.

The above is the entire content of this article, I hope to help you, but also hope that a lot of support cloud Habitat community!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.