css&js實現頂部banner滾動提示效果


以一個小例子來展示滾動提示的代碼部分:

try.html

<div id="scrollobj" >
<span class="scrollTxt">本活動將於2016年8月30日結束,如有抽獎機會,請盡快使用。&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp </span>
</div>

try.css

#scrollobj{
white-space:nowrap;
overflow:hidden;
width:100%;
height: 30px;
line-height: 30px;
background-color: #0553a9;
}
.scrollTxt{
width: 100%;
font-size: 16px;
color: #fff880;
}

try.js

function scroll(obj) {
var tmp = (obj.scrollLeft)++;
//當滾動條到達右邊頂端時
if (obj.scrollLeft==tmp) { obj.innerHTML += obj.innerHTML;}
//當滾動條滾動了初始內容的寬度時滾動條回到最左端
if (obj.scrollLeft>=obj.firstChild.offsetWidth) { obj.scrollLeft=0; }

}
$interval(function(){
scroll(document.getElementById('scrollobj'));
},30);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM