今天小编给大家分享的是JQ实现弹幕效果的方法介绍,相信很多人都不太了解,为了让大家更加了解JQ实现弹幕效果的方法,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。
10年积累的成都网站制作、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有向阳免费网站建设让你可以放心的选择与我们合作。
代码如下,复制即可使用:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>JQ实现弹幕效果</title> <style type="text/css"> *{ padding: 0; margin: 0; } #box{ height:700px; width:1000px; margin: 0 auto; border:1px solid #000000; position: relative; } #main{ width:100%; height:605px; position: relative; overflow: hidden; } p{ position: absolute; left:1000px; width:200px; top:0; } #bottom{ width:100%; height:80px; background: #ABCDEF; text-align: center; padding-top: 15px; position: absolute; left: 0; bottom: 0; } #txt{ width:300px; height:50px; } #btn{ width:100px; height:50px; } </style> </head> <body> <div id="box"> <div id="main"> </div> <div id="bottom"> <input type="text" id="txt" placeholder="请输入内容" /> <input type="button" id="btn" value="发射" /> </div> </div> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> <script type="text/javascript"> $(function(){ var pageH=parseInt($("#main").height()); var colorArr=["#cfaf12","#12af01","#981234","#adefsa","#db6be4","#f5264c","#d34a74"]; $("#btn").bind("click",auto); document.onkeydown=function(e){ if(e.keyCode == 13){ auto(); } }; function auto(){ var $value = $("#txt").val(); $("#main").append("<p>" + $value + "</p>"); $("#txt").val(""); var _top=parseInt(pageH*(Math.random())); var num=parseInt(colorArr.length*(Math.random())); $("p:last-child").css({"top":_top,"color":colorArr[num],"font-size":"20px"}); $("p:last-child").animate({"left":"-200px"},10000); $("p:last-child").stop().animate({"left":"-300px"},10000,"linear",function(){ $(this).remove(); }); //console.log($value); }; }) </script> </body> </html>
以上就是JQ实现弹幕效果的方法介绍的详细内容了,看完之后是否有所收获呢?如果想了解更多相关内容,欢迎来创新互联行业资讯!
本文题目:JQ实现弹幕效果的方法介绍
URL分享:https://www.cdcxhl.com/article26/ijggjg.html
成都网站建设公司_创新互联,为您提供虚拟主机、网站内链、企业网站制作、小程序开发、服务器托管、ChatGPT
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联