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