php+js实现弹幕,js构造对象实现弹幕功能

Document

height: 3000px;

}

#wrap {

position: relative;

width: 1200px;

height: 300px;

background: rgba(215, 221, 222, 1);

border-radius: 10px;

margin: 50px auto;

padding-top: 22px;

overflow: hidden;

}

#wrap .list {

position: absolute;

box-sizing: border-box;

padding:010px;

width: auto;

height: 50px;

overflow: hidden;

color: #333;

text-align: center;

line-height: 50px;

font-size: 14px;

border-radius: 20px;

background: rgba(237, 241, 242, 1)

}

//页面加载完成后执行

window.onload = function() {//创建一个函数

functionbarrage(top, right, num) {//获取到最外层放置弹幕的盒子

var oWrap = document.getElementById("wrap");this.top =top;this.right =right;this.timer = null;//新建一个放弹幕内容的数组

var roll = ["今天是2019年11月8日", "今天天气晴朗", "适合出去玩耍", "无为大佬给我找找bug", "欢迎大家来济南玩"];var len =roll.length;//定义一个初始化方法

this.init = function() {this.oList = document.createElement("div");this.oList.classList.add("list"); //创建一个类名为list的div

oWrap.appendChild(this.oList); //将类名为list的div添加到最外层的盒子

this.oList.style.top = this.top + "px";this.oList.style.right = this.right + "px";this.oList.innerHTML = roll[num %len];

};//设置方法,让弹幕滚动起来

this.roll = function() {//此处需要备份,因为进入setInterval之后this就是window了

var self = this;this.timer = setInterval(function() {

self.right++;if (self.right > 1000) self.die();

self.oList.style.right= self.right + "px";

},10);this.oList.onmouseover = function() {

clearInterval(self.timer);

}};this.die = function() {//清理定时器

clearInterval(this.timer);//清除div

oWrap.removeChild(this.oList);

}//调用初始化方法

this.init();//调用滚动

this.roll();

}//定义信号量

var num = 0;

setInterval(function() {new barrage(Math.random() * 250, -160, num);

num++;

},2000);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值