基于jquery实现弹幕效果

用jquery写的一个弹幕,供大家参考,具体内容如下

效果图:

基于jquery实现弹幕效果

源码:

<html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta content="width=device-width, initial-scale=1"> <!-- <link href="https://www.jb51.net/favicon.ico" type="image/x-icon" /> <link href="https://www.jb51.net/favicon.ico" type="image/x-icon" /> --> <meta content="EditPlus®"> <meta content=""> <meta content=""> <meta content=""> <title>JQuery弹幕</title> <link href="" /> </script> <style type="text/css"> body { overflow: hidden; } .content { overflow: hidden; } .ctxt { background: burlywood; width: 100%; overflow: hidden; margin: 0 auto; z-index: 9999; } .ctxt p { left: 95%; margin: 0; padding: 0; z-index: 99; overflow: hidden; } #msg{ height: 24px; width: 200px; } #barrage { color: gainsboro; border: 1px solid aqua; font-size: 12px; border-radius: 10px; float: right; } #style { margin-top: 10px; } #publish { display: none; } video { width: 100%; overflow: hidden; z-index: -99999; } #danmu { position: absolute; overflow: hidden; font-size:20px; } </style> </head> <body> <div> <div> <video autoplay="autoplay"> <source src="https://www.jb51.net/video/1429411761ed3dc100c73251.mp4" type="video/mp4"> </source> </video> </div> <div> <button> <font>开始弹幕</font></button> <div> <form method="post"> <input type="text" /> <button type="button">发布</button> </form> </div> </div> </div> <script type="text/javascript" src="https://www.jb51.net/js/jquery-2.1.1.min.js" ></script> <script type="text/javascript"> $(document).ready(function() { $("#barrage").click(function() { $("#publish").toggle(); }); $("#submitBut").click(function() { var msgtxt = $("#msg").val(); var colortxt = getReandomColor(); var topPos = generateMixed(3); if(topPos > 500) { topPos = 30; } var newtxt = '<p>' + $("#msg").val() + '</p>'; $(".ctxt").prepend(newtxt); var addTextW = $(".ctxt").find("p").width(); $(".ctxt p").animate({ left: '-' + addTextW + 20 + "px" }, 30000, function() { $(this).hide(); }); $("#msg").val(" "); }); }); //随机获取颜色值 function getReandomColor() { return '#' + (function(h) { return new Array(7 - h.length).join("0") + h })((Math.random() * 0x1000000 << 0).toString(16)) } //生成随机数据。n表示位数 var jschars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; function generateMixed(n) { var res = ""; for(var i = 0; i < n; i++) { var id = Math.ceil(Math.random() * 9); res += jschars[id]; } return res; } </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjypj.html