jQuery如何实现弹幕?jQuery实现弹幕效果的代码

本篇文章给大家带来的内容是关于jquery如何实现弹幕?jquery实现弹幕效果的代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

 jQuery实现弹幕效果的代码如下:

                    JQ实现弹幕效果                    *{                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;                            }                        

$(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("

" + $value + "

"); $("#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); }; })

登录后复制

相关文章推荐:

利用JS实现一个可精确到10ms的秒表的制作(附代码)

如何使用原生JavaScript实现轮播图?代码详解

以上就是jQuery如何实现弹幕?jQuery实现弹幕效果的代码的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2744359.html

(0)
上一篇 2025年3月8日 03:18:57
下一篇 2025年3月3日 08:34:35

AD推荐 黄金广告位招租... 更多推荐

发表回复

登录后才能评论