JavaScript 实现文字上下间隔滚动效果(符合Web标准)

作者:纸飞机时间:2026-10-24 11:45:41浏览:567

本文提供两段符合Web标准的JavaScript文字上下间隔滚动代码。第一段为脚本之家修正版,解决兼容性问题;第二段针对Firefox浏览器进行了优化调整,虽存在部分运行问题,但展示了核心实现思路。代码包含完整的HTML结构与CSS样式,适合用于网站公告栏展示,开发者可直接参考其逻辑进行二次开发。

文字上下间隔滚动修正版

首个实现文字在垂直方向上按时间间隔进行滚动的修正版代码


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>符合WEB标准的文字间隔滚动JS代码</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <style type="text/css"> <!-- body,td,th { font-size: 12px; color: #333333; } a { font-size: 12px; color: #333333; } a:link { text-decoration: none; } a:visited { text-decoration: none; } a:hover { text-decoration: none; color: #FF3300; } a:active { text-decoration: none; } body,div{margin:0; padding:0} --> </style></head> <body>  </body> </html> 

[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]



Firefox兼容性及思路解析

第二个示例在Firefox浏览器中存在运行异常,但JavaScript学习者仍可参考其核心逻辑。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JS文字间隔性滚动代码_适合做公告</title> <meta name="keywords" content="文字滚动,间隔滚动,文字上翻,JS代码" /> <meta name="description" content="JS实现文字间隔性滚动效果,适合做公告。" /> <style type="text/css"> <!-- body{ font-size:12px;} #shangfan{font-family: 新宋体, 宋体, 仿宋_GB2312;font-size: 12px; line-height:24px; height:24px; width:400px; border:solid 1px #ccc;overflow:hidden;} #shangfan ul{margin: 0px 10px;padding: 0px;list-style-type: none;} #shangfan ul li{/*文字超出本行,自动省略*/overflow:hidden;text-overflow:ellipsis;white-space: nowrap;margin:0;padding: 0px;} --> </style> </head> <body> <div id="shangfan"> <div id="holder"> <ul> <li>packer_至强的javascript在线加密工具</li> <li>XHTML 代码嵌套查看工具[标签闭合]</li> <li>本站 在线进制转换 可以实现各类进制间</li> <li>在线JS脚本校验器检测js错误 </li> <li>将html转换为php,javascript和asp的在线工具</li> </ul></div> </div>  </body> </html> 

[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]

作者最新文章