文字列表无缝滚动
HTML代码:
<div id="rule"> <div class="list" id="list"> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> <p>用户185****0000 获得XXX优惠券</p> </div> <div class="list2" id="list2"></div> </div>
JavaScript代码
var speed=50; var list=document.getElementById('list'); var list2=document.getElementById('list2'); var rule=document.getElementById('rule'); list2.innerHTML=list.innerHTML; function Marquee(){ if(list2.offsetTop-rule.scrollTop<=0) rule.scrollTop-=list.offsetHeight; else{ rule.scrollTop++; } } var MyMar=setInterval(Marquee,speed); rule.onmouseover=function() {clearInterval(MyMar)} rule.onmouseout=function() {MyMar=setInterval(Marquee,speed)}