JS back to the top of the instance sharing _javascript tips

Source: Internet
Author: User

If you don't say more, see the example

1, HTML structure

<div class= "Return_top" ></div>

2, CSS style

. return_top{ 
  width:50px; 
  height:50px; 
  Background:url (.. /images/lanren.gif) no-repeat Center #FF8D16; 
  position:fixed; 
  right:30px; 
  bottom:30px; 
  Display:none; 
  Cursor:pointer; 
  z-index:99;
}

3, JS effect

<script>
   $ (function () {
    $ (window). Scroll (function () {
      var topdistance=$ (window). scrolltop ();  Gets the height of the mouse moving in the existing state of this window
      if (topdistance>100) {  //If the move height is greater than 100px, the top icon displays only, if the move height is less than or equal to 100, the top icon does not display
        $ ('. Return_top '). FadeIn (a);
      else{
        $ ('. Return_top '). fadeout (a);
      }
    });
    $ ('. Return_top '). On (' click ', Function () {
      $ (' html,body '). Animate ({scrolltop:0},800);///Must be selected with $ (' html,body ') Otherwise no effect
    })
  ;
</script>

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!

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.