Jquery web page Back to Top Effect (icons fade away, self-write)

Source: Internet
Author: User

Well, come in for development. When there are too many webpages, you need a button to quickly return to the top, instead of rolling the pulley by yourself ~

It was originally difficult to say that the above header should be implemented in Javascript, which page reference and which page display.

As a result, Ben diaosi tried to write it. Well, I didn't find it. It's quite easy to say ~~

If there is a fart, I will be able to put it on the Code directly. If there is more fart, it will become a shit ~~ Oh, sin, Amitabha, amen ~~
Copy codeThe Code is as follows:
<Pre name = "code" class = "javascript"> // return to the top js
$ (Function (){
Var $ btn_top = $ ('<a id = "scrollTopBtn"> </a> ');
Export btn_top.css ({
'Display': 'none ',
'Width': '40px ',
'Height': '40px ',
'Position': 'fixed ',
'Right': '20px ',
'Bottom': '100px ',
'Z-Index': '123'
});
$ ("Body"). append ($ btn_top );
$ ("Body"). on ("click", "# scrollTopBtn", function (){
$ ("Html, body"). animate ({scrollTop: 0}, "slow ");
});
Var $ btn = $ ("# scrollTopBtn ");
If ($ (window). scrollTop ()> 100 ){
$ Btn. fadeIn (600 );
}
$ (Window). scroll (function (){
If ($ (window). scrollTop ()> 100 ){
$ Btn. fadeIn (600 );
} Else {
$ Btn. fadeOut (600 );
}
});
});

Find an image by yourself. Here I use the absolute path "css/web/images/scrollTop.png"

You can directly change the size of line 5 and line 6 to avoid adding cat labels on the page ~~ (> ^ ω ^ <) Meow ~~~

Save it as a js file and reference it directly ~~~

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.