改了一些代碼,但是效果出不來,clientHeight測出來的效果是2803,求各位大神看看哪里出錯(cuò)
window.onload=function(){
var obtn=document.getElementById('btn');
? ??
? ? var timer=null;
? ??
? ? var isTop=true;
? ? var clientHeight=document.documentElement.clientHeight || document.body.clientHeight;
? ? window.onscroll=function(){
? ? ??
? ? ? var osTop=document.documentElement.scrollTop ?|| document.body.scrollTop;
? ? ?if(osTop>=clientHeight){
? ? ? obtn.style.display="block";
? ? }else{
? ? ?obtn.style.display="none";
? ? ?}
? ? ? if(!isTop){
? ? ? clearInterval(timer);
? ? ? }
? ? ? isTop=false;
? ? }
obtn.onclick=function(){
timer=setInterval(function(){
var osTop=document.documentElement.scrollTop || document.body.scrollTop;
var ispeed=Math.ceil(osTop/5);
document.documentElement.scrollTop=document.body.scrollTop=osTop-ispeed;
if(osTop==0){
clearInterval(timer);
}
isTop=true;
},40)
}
}
2017-02-15
我給你測了一下,除了回到頂部放上去沒有回到頂部的這樣外,其他代碼都沒問題。想要測試的話,你還是把課程的素材下下來,自己試一下。注意上面的那個(gè)<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">一定要有,不然不行。
2017-03-27
我自己的代碼就是沒了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">這個(gè)