Js dynamically moves the scroll bar to the bottom of the sample code

  • 2020-03-30 02:41:46
  • OfStack

 
var currentPosition,timer; 
function GoBottom(){ 
timer=setInterval("runToBottom()",50); 
} 
function runToBottom(){ 
currentPosition=document.documentElement.scrollTop || document.body.scrollTop; 
currentPosition+=30; 
if(currentPosition<document.body.scrollHeight && (document.body.clientHeight + document.body.scrollTop < document.body.scrollHeight)) 
{ 
//window.scrollTo(0,currentPosition); 
//alert(document.documentElement.clientHeight + " " + document.documentElement.scrollTop + " " + document.documentElement.scrollHeight + "#" +document.body.clientHeight + " " + document.body.scrollTop + " " + document.body.scrollHeight); 
document.body.scrollTop = currentPosition; 
} 
else 
{ 
document.body.scrollTop = document.body.scrollHeight; 
clearInterval(timer); 
} 
} 

Related articles: