弹幕(转载zhihu)

(function () {
var timer = null;
var spred = [’.’, ‘.’, ‘.’, ‘.’, ‘.’];
var start = 1;
// 加载样式
var fixInp = document.createElement(‘textarea’);
var fixSend = document.createElement(‘input’);
var fixStop = document.createElement(‘input’);
var tips1 = document.createElement(‘p’);
var tips2 = document.createElement(‘span’);
var times = document.createElement(‘input’);
var fixWrap = document.createElement(‘div’);
var outer = document.createElement(‘div’);
var hide = document.createElement(‘span’);
var show = document.createElement(‘span’);
var checkdiv = document.createElement(‘div’);
var checkTip = document.createElement(‘span’);
var check = document.createElement(‘input’);
fixSend.setAttribute(‘type’, ‘submit’);
fixSend.setAttribute(‘value’, ‘发送’);
fixStop.setAttribute(‘type’, ‘submit’);
fixStop.setAttribute(‘value’, ‘停止’);
times.setAttribute(‘type’, ‘number’);
check.setAttribute(‘type’, ‘checkbox’);
tips1.innerHTML = ‘内容:’;
tips2.innerHTML = ‘间隔(秒):’;
hide.innerHTML = ‘隐藏’;
show.innerHTML = ‘显示’;
checkTip.innerHTML = ‘防重复发言:’;
outer.style.cssText = ‘position: fixed; right: 10px; bottom: 10px; display: block; width:200px;padding: 10px; background:#4CAF50;z-index: 9999999;’;
times.style.cssText = ‘display: inline-block; width: 40px;’;
fixInp.style.cssText = ‘display: block;width: 100%;height:62px;box-sizing: border-box;’;
tips1.style.cssText = ‘margin:0;padding:0;’;
fixWrap.style.cssText = ‘display: inline-block;width:100%;’;
show.style.cssText = ‘position: fixed; right: 10px; bottom: 10px;display:none;padding:2px; background:#4CAF50;font-size: 12px;color: #fff; cursor: pointer;’;
hide.style.cssText = ‘display:inline-block;padding:2px; background:#b22;font-size: 12px;color: #fff; cursor: pointer;’;
times.value = 10;
fixWrap.appendChild(hide);
fixWrap.appendChild(tips1);
fixWrap.appendChild(fixInp);
fixWrap.appendChild(tips2);
fixWrap.appendChild(times);
fixWrap.appendChild(fixSend);
fixWrap.appendChild(fixStop);
checkdiv.appendChild(checkTip);
checkdiv.appendChild(check);
fixWrap.appendChild(checkdiv);
outer.appendChild(fixWrap);
document.body.appendChild(outer);
document.body.appendChild(show);
// 发送弹幕
function send(message, bool) {
if (bool) {
var s = spred.slice(0, start++);
message += s.join(’’);
if (start > spred.length) {
start = 1
}
}
document.querySelector(’.ChatSend-txt’).value = message;
document.querySelector(’.ChatSend-button’).click();
}
// 事件
fixSend.addEventListener(‘click’, function () {
var time = parseInt(times.value);
var message = fixInp.value;
var bool = check.checked;
fixSend.style.display = ‘none’;
send(message);
timer = setInterval(function () {
send(message, bool);
}, time * 1000);
});
fixStop.addEventListener(‘click’, function () {
fixSend.style.display = ‘inline-block’;
clearInterval(timer);
timer = null;
});
hide.addEventListener(‘click’, function () {
outer.style.display = ‘none’;
show.style.display = ‘inline-block’;
});
show.addEventListener(‘click’, function () {
outer.style.display = ‘block’;
show.style.display = ‘none’;
});
})();

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值