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