本章節介紹一下如何利用原生javascript實現但行文本的不簡單無縫滾動效果。
這種效果在大量的網站都有使用,站點的公告或者其他功能一般會採用這種形式,下面就通過代碼實例簡單介紹一下。
代碼如下:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <!DOCTYPE html>
< html >
< head >
< meta charset = " utf-8" >
< title >熒光屏文字
滾動效果</ title >
< style type = "text/css" >
#scrollobj{
white-space:nowrap;
overflow:hidden;
width:200px;
margin:50px;
}
</ style >
< script type = "text/javascript" >
function scroll(obj){
var tmp=(obj.scrollLeft)++;
if(obj.scrollLeft==tmp){
obj.innerHTML += obj.innerHTML;
}
if(obj.scrollLeft>=obj.firstChild.offsetWidth){
obj.scrollLeft=0;
}
}
setInterval("scroll(document.getElementById('scrollobj'))",20);
</ script >
</ head >
< body >
< div id = "scrollobj" >歡迎您,只有努力奮鬥纔會有美好的未來。</ div >
</ body >
</ html >
|
|