在要写一个弹幕案例的时候,首先要清楚每一步要干什么。
首先搭好框架之后在要发送弹幕时应该准备进行如下步骤:
- 获取到要发送到弹幕上的内容,即获取到文本框输入的内容。通过jquery的var str = $(“#文本框的id”).val();
- 生成一个元素:利用jQuery的 var createSpan =$(““)生成一个span元素,以便发送。
- 给刚创建的span赋值,即获取到的文本框中的值 createSpan.text(str );
- 设置元素的动画效果,是元素动起来。利用jQuery的animate(css样式值,时间, 执行完动画调用的方法)。执行完动画得手动移除刚刚所添加的元素。
里面还有许多细节,仔细看就会有收获!
弹幕案例 html,body{ margin: 0px; padding: 0px; width: 100%; height: 100%; font-family: "微软雅黑"; background: #ccc; } .boxDom{ width: 100%; height: 100%; position: relative; overflow: hidden; } .idDom{ width: 100%; height: 60px; background:#666; position: fixed; bottom: 0px; } .contet{ width: 500px; height: 40px; position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; margin: auto; } .title{ display: inline; font-size: 24px; vertical-align: bottom; color: #ffffff; padding-left: 300px; } .text{ width: 300px; height: 30px; border:none; border-radius:5px; font-size: 20px; margin-left:60px; } .btn{ width: 60px; height: 30px; color: #ffffff; background-color: red; border:none; font-size:16px; margin-left:60px; margin-top: 20px; } .string { width: 300px; height: 40px; margin-top: 20px; position: absolute; color: #000; font-size: 20px; font-family: "微软雅黑"; } 说点什么:
效果图如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



