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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM