
1、模拟数据
const newList = new Array(10000000).fill(1).map((item, index) => {
return {
time: (index + 1) * 1000,
content: `这是第${index + 1}s发送的消息`
}
})
//time发生时间,content发生内容
2、发送的消息列表
const sendList = [];
function getMessage(time) {
let j = 0; // 循环次数
for(let i = 0, len = newList.length; i < len; i++) {
const item = newList[i]; j++;
//如果time是1234、1214这种,就需要取一个浮动范围
if(item.time === time) {
sendList.push(newList[i]) newList.splice(i, 1) i--;
} else if(sendList.length > 0) {
break;
}
}
console.log('播放进度', time)
console.log('循环的次数', j);
console.log('接收的消息的长度', sendList.length, sendList);
console.log('原始消息的长度', newList.length);
}
3、设置定时器
//1s触发一次
let time = 0;
setInterval(() => {
time += 1000;
getMessage(time);
}, 1000)
PouchDB:一款基于JavaScript 的开源NoSQL文档数据库
JavaScript获取指定网站状态码查询代码(2种实现方法)
标签: 弹幕
上面是“前端如何利用javascript实现弹幕数据循环”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2444.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3+js如何做一个动态点赞效果
Paperless文档管理系统:GitHub项目,支持100+语言的OCR
新手必读之原版织梦模板DEDECMS整站源码通用安装
泡泡加速器
VPN虚拟专网软件之EasyConnect