Home > Web Front-end > JS Tutorial > body text

Implement seamless text scrolling effect based on javascript_javascript skills

WBOY
Release: 2016-05-16 15:09:49
Original
1405 people have browsed it

The example in this article shares with you all the JavaScript code to achieve seamless text scrolling for your reference. The specific content is as follows

Rendering:

Implementation code:

<!DOCTYPE html>
<html>
<head>
  <meta charset="gb2312">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <style>
   *{margin:0;padding:0;}
    .div{margin:100px auto 0;width:350px;height:168px; background:#fff;border:5px solid #ccc; border-radius:5px; overflow:hidden;padding:5px; cursor: pointer;}
    .div ul li{list-style:none;height:24px; line-height: 24px; text-overflow:ellipsis; font-size: 12px; white-space:nowrap; overflow: hidden;}
  </style>
</head>
<body>
   <div class="div" id="div">
  <ul>
    <li>1、分看见地上放声大哭了范上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了德萨</li>
    <li>2、分看见地上放声大哭了范上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了德</li>
    <li>3、分看见地声大哭了上放声大哭了上放声大哭了上放声大哭了范德</li>
    <li>4、分看见地上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了范德</li>
    <li>5、分看见地上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了上放声大哭了范德</li>
    <li>6、分看见地上放声大哭了范声大哭了上放声大哭了</li>
    <li>7、分看见地上放声大哭了上放声大哭了上放声大哭了范上放声大哭了上放声大哭了德</li>
    <li>8、分看见地上放声大哭了上放声大哭了上放声大哭了上放声大哭了范德</li>
  </ul>
 </div>
 <script type="text/javascript">
 
 
   var area = document.getElementById('div');
   var iliHeight = 24;//单行滚动的高度
   var speed = 50;//滚动的速度
   var time;
   var delay= 1000;
   area.scrollTop=0;
   area.innerHTML+=area.innerHTML;//克隆一份一样的内容
   function startScroll()
   {
     time=setInterval("scrollUp()",speed);
     area.scrollTop++;
   }
 
   function scrollUp()
   {
     if(area.scrollTop % iliHeight==0)
     {
       clearInterval(time);
       setTimeout(startScroll,delay);
     }else{
       area.scrollTop++;
       if(area.scrollTop >= area.scrollHeight/2){
         area.scrollTop =0;
      }
    }
  }
  setTimeout(startScroll,delay)
 
 </script>
</body>
</html>
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone in javascript programming.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template