谁能帮我一步步分析下JS的 " onmousedown事件 " 代码,指出问题所在.源代码如下:
Documentbody,div,ul,li{
padding: 0;
margin: 0;
font-size: 0;
letter-spacing: -4px;
position: relative;
}
div.all{
width: 400px;
height: 12000px;
margin: 0 auto;
border: 1px solid black;
/*overflow: hidden;*/
}
div span.totop{
display: block;
color: #fff;
background-color: rgba(0, 0, 0, 0.5);
cursor: pointer;
position: fixed;
text-align: center;
width: 60px;
height: 60px;
line-height: 60px;
font-size: 20px;
letter-spacing: 0;
left: 50%;
bottom: 50px;
margin-left: -30px;
}
顶部
var spanTotop= document.querySelector("span.totop");
var itimerAnother,
iPosition;
window.οnscrοll= function(){
iPosition= document.documentElement.scrollTop|| document.body.scrollTop;
console.log(iPosition);
}
spanTotop.οnmοusedοwn= function(){
iPosition= document.documentElement.scrollTop|| document.body.scrollTop;
itimerAnother= setInterval(function(){
iPosition= iPosition- Math.ceil(iPosition/ 10);
document.documentElement.scrollTop= iPosition;
document.body.scrollTop= iPosition;
},10);
if(iPosition<= 0){
clearInterval(itimerAnother);
// 为什么把 clearInterval 放在外面清除不了 setInterval -------------------------
// 放在 setInterval 里面就可以 ---------------------------
}
}
先谢谢了...