全国统一服务热线:400-633-9193

javascript实现文字无缝滚动效果

    网络     2017-09-14    1359

本文实例为大家分享了文字无缝滚动效果,供大家参考,具体内容如下

html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<dl id="marquee" class="marquee">
  <dt>
    <ul class="right-content">
      <li>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="orderNum">BKCSHC161014002153</a>
      </li>
      <li>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="orderNum">BKCSHC161014002153</a>
      </li>
      <li>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="orderNum">BKCSHC161014002153</a>
      </li>
      ...
    </ul>
  </dt>
  <dd></dd>
</dl>

js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<script>
    $(function(){
        Marquee("marquee");
    })
 
    //订单滚动
    var Marquee = function(id){
      var container = document.getElementById(id),
      original = container.getElementsByTagName("dt")[0],
      clone = container.getElementsByTagName("dd")[0],
      liLength=original.getElementsByTagName("li").length,
      speed = 55;
      if(liLength<=8){
        return
      }
      clone.innerHTML = original.innerHTML;
 
      var rolling = function(){
        if (container.scrollTop === clone.offsetHeight) {
          container.scrollTop = 0;
        }
        else {
          container.scrollTop++;
        }
      }
      var timer = setInterval(rolling, speed)//设置定时器
      container.onmouseover = function(){
        clearInterval(timer)
      }//鼠标移到marquee上时,清除定时器,停止滚动
      container.onmouseout = function(){
        timer = setInterval(rolling, speed)
      }//鼠标移开时重设定时器
    }   
 </script>

以上就是本文的全部内容,希望对大家的学习有所帮助


  分享到:  
0.2008s