JS控制div上下滚动内容

<html>

<head>
<meta charset="gb2312"></head>

<body>

<div id="father" style="height:100px; overflow:hidden">//这两个属性是必须加上的

<div id="son1">

我是第一行<br>

我是第二行<br>

我是第三行<br>

我是第四行<br>

。。。。。<br>

我是第N行<br>

</div>

<div id="son2"></div>

</div>

</body>

</html>

<script type="text/javascript">

var scrollSpeed=50;//值越大,滚动的越慢

son2.innerHTML=son1.innerHTML;

function ScrollMarquee(){

if(son2.offsetTop-father.scrollTop<=0){

father.scrollTop-=son1.offsetHeight;

}

else{

father.scrollTop++;

}

}

var ScrollTime=setInterval(ScrollMarquee,scrollSpeed);

//father.onmouseover=function(){clearInterval(ScrollingMar);};//鼠标放在上面停止滚动

//father.onmouseout=function(){ScrollTime=setInterval(ScrollMarquee,scrollSpeed);};//鼠标离开,重新滚动

</script>

posted @ 2020-03-19 16:23  FakLove  阅读(2139)  评论(0编辑  收藏  举报