不间断轮播跑马灯效果
分类:实例代码
分享一段代码实例,它实现了不间断轮播的跑马灯效果。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <style> body, p { margin: 0; } .marquee { margin: 50px auto; width: 300px; font-size: 0; overflow-x: hidden; background-color: #ccc; } .wrapper { display: inline-block; white-space: nowrap; } .marquee.play .wrapper { animation: marquee 5s linear infinite; } .text { display: inline-block; margin-right: 50px; color: red; font-size: 16px; line-height: 2; } /*跑马灯播放样式*/ @keyframes marquee { to { transform: translateX(-50%); } } </style> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> <script> $(document).ready(function () { var $marquee = $('.marquee'), $text = $marquee.find('.text'); if ($text.width() > $marquee.width()) { $text.after($text.clone()); $marquee.addClass('play'); } }) </script> </head> <body> <div class="marquee"> <div class="wrapper"> <p class="text">本站的url地址是www.pipipi.net,欢迎提供有益的建议</p> </div> </div> </body> </html>
不间断轮播跑马灯效果,这样的场景在实际项目中还是用的比较多的,关于不间断轮播跑马灯效果就介绍到这了。
不间断轮播跑马灯效果属于前端实例代码,有关更多实例代码大家可以查看。