解决思路:
在box 盒子中停机一个P标签,P标签拥有弹幕效果
让p标签拥有弹幕效果的动画效果,left的大小取决于box的宽
以下是代码
html
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;
}
JQ
$(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);
};
})
效果图:
在输入框里输入,点击发射就可以发送弹幕
0条评论