欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

javascript实现文字无缝滚动效果

程序员文章站 2022-04-29 08:32:51
本文实例为大家分享了文字无缝滚动效果,供大家参考,具体内容如下 html
...

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

html

<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

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

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