jQuery如何实现弹幕?jQuery实现弹幕效果的代码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jQuery如何实现弹幕?jQuery实现弹幕效果的代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2064字,纯文字阅读大概需要3分钟。
内容图文
![jQuery如何实现弹幕?jQuery实现弹幕效果的代码](/upload/InfoBanner/zyjiaocheng/286/0cba4aa50d964cc1ac481d8b2edc7bd2.jpg)
jQuery实现弹幕效果的代码如下:
<!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> <p id="box"> <p id="main"> </p> <p id="bottom"> <input type="text" id="txt" placeholder="请输入内容" /> <input type="button" id="btn" value="发射" /> </p> </p> <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>
相关文章推荐:
利用JS实现一个可精确到10ms的秒表的制作(附代码)
如何使用原生JavaScript实现轮播图?代码详解
以上就是jQuery如何实现弹幕?jQuery实现弹幕效果的代码的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的jQuery如何实现弹幕?jQuery实现弹幕效果的代码全部内容,希望文章能够帮你解决jQuery如何实现弹幕?jQuery实现弹幕效果的代码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。