我這里哪里出錯(cuò)了,滾動(dòng)條動(dòng)不了呀,明明是照著老師的步驟一步一步來(lái)的
//頁(yè)面加載完觸發(fā)
window.onload=function () {
? ?var obtn = document.getElementById('btn');
? ?var timer=null;
? ?var ?istop=true;
? ? //滾動(dòng)條滾動(dòng)時(shí)出發(fā)
? ?window.onscroll=function () {
? ? ? ?if (!istop){
? ? ? ? ? ?clearInterval(timer);
? ? ? ?}
? ? ? ?istop=false;
? ?}
? ?obtn.onclick=function () {
? ? ? ?//設(shè)置定時(shí)器
? ? ? ?timer=setInterval(function () {
? ? ? ? ? ?//獲取滾動(dòng)條距離頂部的高度
? ? ? ?var ostop=document.documentElement.scrollTop || document.body.scrollTop;
? ? ? ? ? ?var ispeed=math.floor(-ostop/6);
? ? ? ?document.documentElement.scrollTop = document.body.scrollTop =ostop+ispeed;
? ? ? ? ? ?istop=true;
? ? ? ? ? ?console.log(ostop-ispeed);
? ? ? ? ? ?if (ostop==0){
? ? ? ? ? ? ? ?clearInterval(timer);
? ? ? ? ? ?}
? ? ? ?},30);
? ?}
}
2017-04-25
document.documentElement.scrollTop = document.body.scrollTop =ostop+ispeed;
你這個(gè)連續(xù)賦值是不是有問(wèn)題
2018-06-12
你那個(gè)math.floor(),math應(yīng)該寫成Math.floor(),才可以