JS实现的新闻列表自动滚动效果示例
程序员文章站
2023-12-09 21:17:51
本文实例讲述了js实现的新闻列表自动滚动效果。分享给大家供大家参考,具体如下:
本文实例讲述了js实现的新闻列表自动滚动效果。分享给大家供大家参考,具体如下:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>title</title> <style type="text/css"> #box{width:260px;height:100px;margin:0 auto;border:2px solid red;overflow: hidden} ul{padding:0;margin:0;list-style: none;overflow: hidden} ul li{height:24px;line-height: 24px;padding-left:10px;} a{text-decoration: none;color:#000;} a:hover{color:#f00} </style> </head> <body> <div id="box"> <ul id="con1" onmouseout="up()" onmouseover="stop()"> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1,课程html</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2,课程css</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3,课程js</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4,课程jquery</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5,课程html5</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >6,课程css3</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >7,课程hp</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >8,课程bpootstrap</a> </li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >9,课程apicloud</a> </li> </ul> <ul id="con2"></ul> </div> </body> <script type="text/javascript"> var box=document.getelementbyid("box"); var con1=document.getelementbyid("con1"); var con2=document.getelementbyid("con2"); var s=document.getelementsbytagname("a"); var speed=50; con2.innerhtml=con1.innerhtml; function scrollup(){ if( box.scrolltop>=con1.scrollheight){ box.scrolltop=0; }else box.scrolltop++; } var i=setinterval("scrollup()",speed); function stop(){ clearinterval(i); } function up(){ i=setinterval("scrollup()",speed); } </script> </html>
这里使用在线html/css/javascript代码运行工具:http://tools.jb51.net/code/htmljsrun测试上述代码,可得如下运行效果:
更多关于javascript相关内容感兴趣的读者可查看本站专题:《javascript切换特效与技巧总结》、《javascript查找算法技巧总结》、《javascript错误与调试技巧总结》、《javascript数据结构与算法技巧总结》、《javascript遍历算法与技巧总结》及《javascript数学运算用法总结》
希望本文所述对大家javascript程序设计有所帮助。