js实现文字无缝向上滚动
2019/6/27 21:09:45
本文主要是介绍js实现文字无缝向上滚动,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
静态效果如下:(动态效果复制粘贴下面代码可见)
代码如下:
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <style type="text/css"> *{ padding: 0; margin:0; } ul,li{ list-style: none } .scroll { height:90px; width:100%; max-width:640px; background-color:#000; overflow:hidden; color: #fff; } .scroll ul { width:100%; position:absolute; left:0; top:0; } .scroll span { font-size:20px; height:30px; /*color:#D83E21; */ } .scroll li { height:30px; line-height:30px; } </style> </head> <body> <div id="scroll" class="scroll clearfix"> <ul> <li>444444444444444444444444</li> <li>11111111111111111111111111</li> <li>11111111111111111111111111</li> <li>11111111111111111111111111</li> <li>11111111111111111111111111</li> <li>33333333333333333333333333</li> <li>11111111111111111111111111</li> <li>11111111111111111111111111</li> <li>11111111111111111111111111</li> <li>11111111111111111111111111</li> <li>11111111111111111111111111</li> <li>2222222222222</li> </ul> </div> </body> </html> <script type="text/javascript"> //滚动 var scrollIndex=0; var Timer=null; function scroll_f(){ clearInterval(Timer); var ul=$("#scroll ul"); var li=ul.children("li"); var h=li.height(); var index=0; ul.css("height",h*li.length*2); ul.html(ul.html()+ul.html()); function run() { if(scrollIndex>=li.length){ ul.css({top:0}); scrollIndex=1; ul.animate({top:-scrollIndex*h},200); } else{ scrollIndex++; ul.animate({top:-scrollIndex*h},200); } } Timer=setInterval(run,1500); } $(function(){ scroll_f(); }) </script>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持找一找教程网!
这篇关于js实现文字无缝向上滚动的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-06vue 新建功能多条数据(还没和后端交互)还能看详情 数据是前端缓存到本地吗?-icode9专业技术文章分享
- 2024-05-30React Native常用组件-点击组件
- 2024-05-30uniapp+vue3+uv-ui手机端后台OA管理模板
- 2024-05-29Python网络爬虫的时候json=就是让你少写个json.dumps()
- 2024-05-27React Native常用组件-展示组件
- 2024-05-27React Native常用组件-列表组件
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode