Using jquery to achieve variable transparency returns top effect

Source: Internet
Author: User
1. Add a tag to the page (HTML) <body></body> (back to top hyperlink)

<a href= "#0" class= "Cd-top" >Top</a>

2, add CSS style (can be written in the page, can also be written in a separate CSS style table)

. cd-top {  display:inline-block;  height:40px;  width:40px;  position:fixed;  bottom:40px;  right:10px;  box-shadow:0 0 10px rgba (0, 0, 0, 0.05);  /* Image Replacement Properties */  Overflow:hidden;  text-indent:100%;  White-space:nowrap;  Background:rgba (232, 98, 0.8) URL (.. /IMAGES/CD-TOP-ARROW.SVG) no-repeat Center 50%;  Visibility:hidden;  opacity:0;  -webkit-transition:all 0.3s;  -moz-transition:all 0.3s;  Transition:all 0.3s;}. cd-top.cd-is-visible {/  * the button becomes visible */  visibility:visible;  Opacity:1;}. cd-top.cd-fade-out {  /* If the user continues to scroll down, the transparency of this button becomes lower *  /opacity:. 5;}. No-touch. cd-top:hover {  background-color: #e86256;  Opacity:1;} @media only screen and (min-width:768px) {  . cd-top {    right:20px;    bottom:20px;}  } @media only screen and (min-width:1024px) {  . cd-top {    height:60px;    width:60px;    right:30px;    bottom:30px;}  }

3, add JS code (before adding JS, must first refer to the jquery library, otherwise it will expire)

<script type= "Text/javascript" src= "http://apps.bdimg.com/libs/jquery/ 2.1.4/jquery.min.js "></SCRIPT> 
$ (document). Ready (function ($) {//browser window scroll (in pixels) after which The "Back to Top" link was shownvar offset = 300,//browser window scroll (in pixels) after which the ' back to top ' link OPA  City was reducedoffset_opacity = 1200,//duration of the top scrolling animation (in ms) Scroll_top_duration = 700,//grab the "Back to top" Link$back_to_top = $ ('. Cd-top '),//hide or show the "Back to Top" link$ (Windows). Scroll (function () {($ (this). ScrollTop () > Offset)? $back _to_top.addclass (' cd-is-visible '): $back _to_top.removeclass (' cd-is-visible cd-fade-out '); ScrollTop () > Offset_opacity) {$back _to_top.addclass (' cd-fade-out ');}}); /www.sucaijiayuan.com//smooth Scroll to Top$back_to_top.on (' click ', Function (event) {Event.preventdefault (); $ (' Body , HTML '). Animate ({scrolltop:0,}, Scroll_top_duration);}); 

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.