为什么滚动到顶的时候会顿一下呢?
window.onload = function(){
var area = document.getElementById('moocBox');
var con1 = document.getElementById('con1');
var con2 = document.getElementById('con2');
con2.innerHTML = con1.innerHTML;
function scrollUp(){
if(area.scrollTop >= area.offsetHeight){
area.scrollTop = 0;
}else{
area.scrollTop ++;
}
}
var timer = setInterval(scrollUp,50); //setInterval引用传参,第一个直接写函数名,不用加引号,第二个参数写时间;
area.onmouseover = function(){
clearInterval(timer);
}
area.onmouseout = function(){
timer = setInterval(scrollUp,50);
}
}
在第九段文字到顶后,会小顿一下,感觉就是
if(area.scrollTop >= area.offsetHeight+15){
area.scrollTop = 0;
}这一段,把area.scrollTop = 0重置为0的时候顿的