Home  >  Article  >  Web Front-end  >  How to achieve seamless scrolling of text list in js?

How to achieve seamless scrolling of text list in js?

零下一度
零下一度Original
2017-06-27 15:36:101627browse

This article mainly introduces the seamless scrolling effect of js text list, which has certain reference value. Interested friends can refer to it

The example of this article shares with everyone the seamless scrolling effect of js text list. The specific code for scrolling is for your reference. The specific content is as follows

HTML code:


<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>

JavaScriptCode


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)}

The above is the detailed content of How to achieve seamless scrolling of text list in js?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn