js弹幕
<html>
<head>
<title>javascript弹幕</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style>
#play{
width:600px;
height:200px;
background-color:#000;
}
#tangmu{
width:600px;
height:200px;
background-color:#fff;
z-index:9999;
background-color: rgba(000, 1, 000, 0.1);
}
.tmf{
position:absolute;
font-size:24px;
color:#fff;
height:24px;
}
</style>
</head>
<body>
<br />
<br />
<br />
<br />
<br />
<div id="play">
<div id="tangmu">
<font class="tmf" id="t1" >檀木</font>
<font class="tmf" id="t2">红米</font>
<font class="tmf" id="t3" >大妈</font>
<font class="tmf" id="Font1" >檀木</font>
<font class="tmf" id="Font2">红米</font>
<font class="tmf" id="Font3" >大妈</font>
<font class="tmf" id="Font4" >檀木</font>
<font class="tmf" id="Font5">红米</font>
<font class="tmf" id="Font6" >大妈</font>
<font class="tmf" id="Font7" >檀木</font>
<font class="tmf" id="Font8">红米</font>
<font class="tmf" id="Font9" >大妈</font>
<font class="tmf" id="Font10" >檀木</font>
<font class="tmf" id="Font11">红米</font>
<font class="tmf" id="Font12" >大妈</font>
<font class="tmf" id="Font13" >檀木</font>
<font class="tmf" id="Font14">红米</font>
<font class="tmf" id="Font15" >大妈</font>
<font class="tmf" id="Font16" >檀木</font>
<font class="tmf" id="Font17">红米</font>
<font class="tmf" id="Font18" >大妈</font>
<font class="tmf" id="Font19" >檀木</font>
<font class="tmf" id="Font20">红米</font>
<font class="tmf" id="Font21" >大妈</font>
<font class="tmf" id="Font22" >檀木</font>
<font class="tmf" id="Font23">红米</font>
<font class="tmf" id="Font24" >大妈</font>
</div>
</div>
<script src="js/jquery-1.7.2.min.js"></script>
<script>
var times = 4000;//时间,定义速度
var hdjgtime = 500;//滑动间隔
var jgtime = 0;
var tmu = 1;
var fjid = "tangmu";//夫级id
var itemclass = "tmf";//子集class
function tm() {
times = 5000;
jgtime = 1000;
jgtime = 0;
$(".tmf").each(function () {
tangmu($(this).attr("id"));
});
}
tm();//页面初始调用
function tangmu(id){
var tangmu = document.getElementById(fjid);
var mathHeight = Math.round(Math.random()*(tangmu.offsetHeight))+"px";
var textLeft=tangmu.offsetWidth+"px";
var textStyleObj = document.getElementById(id);
textStyleObj.style.marginLeft = textLeft;
if (Number(mathHeight.replace("px","")) > (tangmu.offsetHeight - textStyleObj.offsetHeight)) {
mathHeight = (tangmu.offsetHeight - textStyleObj.offsetHeight)+"px";
}
textStyleObj.style.marginTop = mathHeight;
setTimeout(function () {
if ($("#" + id).index() == $("." + itemclass).length - 1)
{ $("#" + id).animate({ "margin-left": "-100px" }, times, function () { tm(); }); }
else
{ $("#" + id).animate({ "margin-left": "-100px" }, times); }
}, jgtime);
var tisj= Math.floor(Math.random() * 10 + 1);
jgtime = jgtime + hdjgtime;//每个追加一秒
}
</script>
</body>
</html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。