当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS特效代码:实现间歇无缝文字滚动特效

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JS特效代码:实现间歇无缝文字滚动特效


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-03   浏览: 344 ::
收藏到网摘: n/a

处理页面中的间歇无缝滚动新闻的时候,最常见的方法就是将滚动区内容复制追加一份,然后通过控制和判断滚动块的scrollTop来实现滚动停止效果。

其实在很多情况下通过节点操作实现间歇无缝滚动要更加容易些。

代码如下:

<script language="javascript" type="text/javascript">
window.onload=function(){
    var o=document.getElementById('box');
    window.setInterval(function(){scrollup(o,24,0);},3000);
}
///滚动主方法
///参数:o 滚动块对象
///参数:d 每次滚屏高度
///参数:c 当前已滚动高度
function scrollup(o,d,c){
    if(d==c){
        var t=getFirstChild(o.firstChild).cloneNode(true);
        o.removeChild(getFirstChild(o.firstChild));
        o.appendChild(t);
        t.style.marginTop="0px";
    }else{
        c+=2;
        getFirstChild(o.firstChild).style.marginTop=-c+"px";
        window.setTimeout(function(){scrollup(o,d,c)},20);
    }
}
//解决firefox下会将空格回车作为节点的问题
function getFirstChild(node){
  while (node.nodeType!=1)
  {
         node=node.nextSibling;
  }
  return node;
}
</script>
<ul id="box">
    <li>· 新华每日电讯:音乐版权收费像“一团麻” </li>
    <li>· 现代快报:人类能否和机器人结婚生孩子? </li>
    <li>· 环球:美国,一家亿万富翁俱乐部的破产 </li>
    <li>· 现代快报:为让媒体封口倪震欲卖李嘉欣情书 </li>
    <li>· 京华时报:北京航空航天大学学生自制火箭升天 </li>   
</ul>

效果:

运行代码框

[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]