首頁  >  文章  >  web前端  >  js怎麼實現文字清單無縫滾動?

js怎麼實現文字清單無縫滾動?

零下一度
零下一度原創
2017-06-27 15:36:101589瀏覽

這篇文章主要介紹了js實現文字清單無縫滾動效果,具有一定的參考價值,有興趣的小伙伴們可以參考一下

本文實例為大家分享了js文字列表無縫捲動的具體程式碼,供大家參考,具體內容如下

HTML程式碼:


#
<p id="rule">
        <p 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>
        </p>
   <p class="list2" id="list2"></p>
</p>

##JavaScript


################################################################################################################################################ ##########
var speed=50;
var list=document.getElementById(&#39;list&#39;);
var list2=document.getElementById(&#39;list2&#39;);
var rule=document.getElementById(&#39;rule&#39;);
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)}

以上是js怎麼實現文字清單無縫滾動?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn