Use jQuery to return to the top of the page

Source: Internet
Author: User
The icons at the top of the page are used to make it easier to preview the page. This function is also a common feature in the website. Today I have studied a simple example, use jQuery to return to the top: css code: * {margin: 0; padding: 0 ;}# backToTop {positi... syntaxHighlighter. a

The icons at the top of the page are used to make it easier to preview the page. This function is also a common feature in the website. Today I have studied a simple example, use jQuery to return to the top:


The css code is as follows:

* {Margin: 0; padding: 0 ;}
# BackToTop {position: fixed; bottom: 10px; left: 80px; _ position: absolute; _ left: 80px; _ bottom: auto ;}
# BackToTop a {text-align: center; text-decoration: none; color: # d1d1d1; display: block; width: 80px;-moz-transition: color 1 s;
-Webkit-transition: color 1 s;-o-transition: color 1 s; width: 18px; background: # 03F ;}
# BackToTop a: hover {color: #979797 ;}


The html code is as follows:


Back to Top

 

The jQuery code is as follows:

 

$ (Document). ready (function (){
Var backTop = $ ("# backToTop ")
BackTop. hide ();
$ (Function (){

$ (Window). scroll (function (){
If ($ (window). scrollTop ()> 100 ){
BackTop. fadeIn (1500 );

}
Else {
BackTop. fadeOut (1500 );
}
})
BackTop. click (function (){
$ ('Body, html '). animate ({scrollTop: 0}, 1000 );

})
})
})


Author: yilanyoumeng3
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.