Chrome page get bindings back top animated event plugin

Source: Internet
Author: User

Under Chrome browser page load:

var top = $ ("Body"). ScrollTop ();

Console.log (top)//event listener is not valid

var top = $ ("html"). ScrollTop ();

Console.log (top)//event listener is not valid

var top = $ (document). ScrollTop ();

Console.log (top)//event listener is not valid

Under the browser window scrolling event listener

$ (window). Scroll (function () {

var top = $ ("Body"). ScrollTop ();

Console.log (top); Event Monitor heard scroll count, no value, default 0;

var top = $ ("html"). ScrollTop ();

Console.log (top); OK, value starting from 1

var top = $ (document). ScrollTop ();

Console.log (top); OK, value starting from 1

}

Ui-backtop back to top plug-inUi.scss

. ui-backtop{
Display:none;
position:fixed;
right:2%;
bottom:10px;
Z-index:9;
width:35px;
height:35px;
border-radius:50%;
Background:url (.. /img/icon-go-up.png) Center No-repeat Rgba (142,223,243,0.8);
&:hover{
Background:rgba (142,223,243,0.4);
color: #00b3ea;
//font-weight:600;
                  }
&:hover:after{
content: "Top";
Display:block;
line-height:35px;
Text-align:center;
font-size:20px;
                 }
             }

Ui.js

$.fn. Uibacktop = function () {
var UI = $ (this);
var el = $ ("<a href= ' # ' class= ' ui-backtop ' ></a>");
var windowheight = $ (window). Height ();
ui.append (EL);
$ (window). Scroll (function () {
var top = $ ("html"). scrolltop ();
if (Top > Windowheight| | top>100) {
el.show ();
}else{
el.hide ();
                     }
              });
El.click (function () {
if ($ ("html"). ScrollTop ()) {
$ ("html"). Animate ({scrolltop:0}, 1000); //In the Click event function Console.log ($ ("html"). ScrollTop ()) is there a value?
return false;
                    };
              });
         }

Although the plug-in functionality to achieve, but as a novice I still leave doubt, the issue of red font Welcome to exchange, thank you!

Chrome page Get bindings return top animated event plug-ins

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.