- 资讯首页 > 开发技术 > web开发 > JavaScript >
- jQuery实现大屏滚动播放效果
本文实例为大家分享了jQuery实现大屏滚动播放效果的具体代码,供大家参考,具体内容如下
场景需求:
在大屏幕上,消息会进行一个实时滚动播报的效果,将现有的内容进行一个来回滚动的播放。
代码:
<!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>复选框checkbox自定义样式</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <style> * { margin: 0; padding: 0; } .contScend { width: 400px; height: 200px; background: #000000; margin: 20px auto; overflow: hidden; } .contScend ul { list-style: none; width: 100%; height: 100%; color:red; font-size: 13px; } .contScend ul li { width: 100%; height: 40px; box-sizing: border-box; line-height: 40px; text-align: center; } </style> </head> <body> <!-- 中间部分 --> <div class="contScend"> </div> </body> <script type="text/javascript"> $.ajax({ url: "test.json", type: 'GET', dataType: 'json', success: function(data) { var html = ""; html += '<ul>'; $.each(data, function(i, item) { // html += '<li>' + item.name + ':' + item.numb + '人' + '</li>'; }); html += '</ul>'; $(".contScend").html(html); scroll(); } }); function scroll() { //获得当前<ul> var $uList = $(".contScend ul"); var timer = null; //触摸清空定时器 $uList.hover(function() { clearInterval(timer); }, function() { //离开启动定时器 timer = setInterval(function() { scrollList($uList); }, 1000); }).trigger("mouseleave"); //自动触发触摸事件 //滚动动画 function scrollList(obj) { //获得当前<li>的高度 var scrollHeight = $("ul li:first").height(); //滚动出一个<li>的高度 $uList.stop().animate({ marginTop: -scrollHeight }, 600, function() { //动画结束后,将当前<ul>marginTop置为初始值0状态,再将第一个<li>拼接到末尾。 $uList.css({ marginTop: 0 }).find("li:first").appendTo($uList); }); } } </script> </html>
test.json
[{ "name": "体验区统计", "numb": 0 }, { "name": "test909", "numb": 0 }, { "name": "test910", "numb": 0 }, { "name": "111", "numb": 0 }, { "name": "test", "numb": 0 }, { "name": "test11111", "numb": 0 }, { "name": "记忆区统计", "numb": 0 }]
效果如下
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
免责声明:本站发布的内容(图片、视频和文字)以原创、来自互联网转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:ts@56dr.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
Copyright © 2009-2021 56dr.com. All Rights Reserved. 特网科技 版权所有 珠海市特网科技有限公司 粤ICP备16109289号
域名注册服务机构:阿里云计算有限公司(万网) 域名服务机构:烟台帝思普网络科技有限公司(DNSPod) CDN服务:阿里云计算有限公司 中国互联网举报中心 增值电信业务经营许可证B2 建议您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流浏览器浏览本网站