代碼如下:
<body>
//借助于marquee
<marquee behavior=scroll contenteditable=true onstart=this.firstchild.innerhtml+=this.firstchild.innerhtml; scrollamount=3 width=100>
<span unselectable=on>這里是要滾動(dòng)的內(nèi)容</span>
</marquee>
//普通的實(shí)現(xiàn)方法
<div id=scrollobj style=white-space:nowrap;overflow:hidden;width:500px;>
<span>這里是要滾動(dòng)的內(nèi)容</span>
</div>
<script language=javascript type=text/javascript>
function scroll(obj) {
var tmp = (obj.scrollleft)++;
//當(dāng)滾動(dòng)條到達(dá)右邊頂端時(shí)
if (obj.scrollleft==tmp) obj.innerhtml += obj.innerhtml;
//當(dāng)滾動(dòng)條滾動(dòng)了初始內(nèi)容的寬度時(shí)滾動(dòng)條回到最左端
if (obj.scrollleft>=obj.firstchild.offsetwidth) obj.scrollleft=0;
}
setinterval(scroll(document.getelementbyid('scrollobj')),20);
</script>
</body>