Home > front end >  Bosses have a look at why didn't clear the timer function, with the help of continuous click wi
Bosses have a look at why didn't clear the timer function, with the help of continuous click wi

Time:11-02

& lt; ! DOCTYPE html>


<meta charset="utf-8" & gt;


<style>
The aaa {
Height: 10000 px;
Background: # 000000;
}
</style>
<body>




<script SRC="https://bbs.csdn.net/js/huidaodingbu.js" & gt; </script>
<script type="text/javascript">
Var gou=new goTop ({
The container: "goto"
})
</script>


Js code:
(function (w, d) {
Var defautSettings={
Position: "fixed",
Width: "35 px",
35 px height: ", "
Right: "30 px",
Bottom: "30 px",
Cursor: "pointer",
BackgroudColor: "# 7 a6e6e,"
BorderRadius: "three 3 px 0 0 px",
}
The function goTop (options) {
Var self=this;
The self=Object. The assign (self, options, defautSettings);
Self. _setStyle ();
Self. _setEvent ();
}
GoTop. Prototype={
_setStyle: function () {
Var self=this;
Var gotoDom=d.g etElementById (self. The container);
For (var I in self) {
If (I.="container" & amp; & i!="_setStyle" & amp; & i! {
="_setEvent")GotoDom. Style [I]=self [I];
}
}
},
_setEvent: function () {
Var self=this;
Var gotoDom=d.g etElementById (self. The container);
GotoDom. Onclick=function () {
ClearInterval (times);
Var times=setInterval (function () {
If (d.d ocumentElement. ScrollTop & gt; 0 {
D.d. OcumentElement scrollTop=d.d ocumentElement. ScrollTop - 10;
} else {
ClearInterval (times);
}
}, 1);
}
}
}
W.g oTop=goTop;
}) (Windows, the document)

CodePudding user response:

 
_setEvent: function () {
var self=this;
Var gotoDom=d.g etElementById (self. The container);
Var times;
GotoDom. Onclick=function () {
ClearInterval (times);
Times=setInterval (function () {
If (d.d ocumentElement. ScrollTop & gt; 0 {
D.d. OcumentElement scrollTop=d.d ocumentElement. ScrollTop - 10;
} else {
ClearInterval (times);
}
}, 1);
}
}
}
  • Related