標籤:完整 http script pad size 文檔 nload hidden class
實現思路
定義兩個滾動塊,內容一模一樣,從下往上兩個緊挨著滾動,當第一個滾動塊滾動出容器時(即第二個滾動塊頂到了容器的上邊緣),此時我們將第一個滾動塊設定位置到容器上邊緣,由於兩個滾動塊一模一樣,從效果上我們也看不出來容器的內容發生了替換。
html 代碼
<div class="box" id="box"> <ul class="col1" id="col1"> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> </ul> <ul class="col2" id="col2"> <li>2</li> <li>2</li> <li>2</li> <li>2</li> <li>2</li> <li>2</li> <li>2</li> <li>2</li> <li>2</li> </ul></div>
為了區分效果,我將兩個塊分別內容設為1和2.
css 代碼
.box { position: relative; width: 100px; height: 90px; overflow: hidden; border: solid 1px;}.col1, .col2 { height: 200px; position: absolute;}.col2 { top:200px; } /* 讓第二列頂著第一列的末尾*/
js 代碼
var LEN = 200; // 一個完整捲軸的長度var x = 0;var t;window.onload = roll;function roll() { var $col1 = document.getElementById("col1"); var $col2 = document.getElementById("col2"); var fun = function(){ $col1.style.top = x + ‘px‘; $col2.style.top = (x + LEN) + ‘px‘; x--; if( (x + LEN) == 0 ){ x = 0; } }; t = setInterval(fun,1000);}// 可以再加上滑鼠移入停止滾動的函數
其他:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>無標題文檔</title> <style> @-webkit-keyframes move { 0%{ left:0; } 100% { left:-500px; } } #wrap{ width:500px;height:100px;border:1px solid #000; position:relative;margin:100px auto; overflow:hidden;} #list{ position:absolute;left:0;top:0;margin:0;padding:0; -webkit-animation:3s move infinite linear; width:200%;} #list li{ list-style:none;width:98px;height:98px;border:1px solid #fff;background:#000; color:#fff; font:50px/98px Arial; text-align:center; float:left;} #wrap:hover #list{ -webkit-animation-play-state:paused;} </style> </head> <body> <div id="wrap"> <ul id="list"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </body> </html>
CSS/JS實現無縫滾動字幕