js實現(xiàn)文字無縫向上滾動
更新時間:2017年02月16日 11:46:39 作者:大大大大糖糖
本文主要分享了js實現(xiàn)文字無縫向上滾動的示例代碼,具有很好的參考價值,下面跟著小編一起來看下吧
靜態(tài)效果如下:(動態(tài)效果復制粘貼下面代碼可見)
代碼如下:
<!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>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關文章
JavaScript深入淺出__proto__和prototype
這篇文章主要介紹了JavaScript深入淺出__proto__和prototype,文章基于JavaScript的相關資料展開詳細的內(nèi)容介紹。具有一定的參考價值,需要的小伙伴可以參考一下2022-05-05Javascript學習之談談JS的全局變量跟局部變量(推薦)
這篇文章主要介紹了Javascript學習之談談JS的全局變量跟局部變量雖然腳本之家小編以前發(fā)過,但還是這篇文章整理的比較好,需要的朋友可以參考一下2016-08-08基于bootstrap的文件上傳控件bootstrap fileinput
這篇文章主要為大家詳細介紹了基于bootstrap的文件上傳控件bootstrap fileinput,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12