web建站教程
     
  1. 首页
  2. 前端UI组件库
  3. AI项目和框架
  4. AIGC工具
  5. 百度echarts
  6. 地图大全
  7. 前端知识
  8. 更多
    vuejs
    js入门
    php入门
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    AI应用

前端如何利用javascript实现弹幕数据循环

660 ℃

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)

愛彈幕網官网入口网址,专注于动画与番剧的弹幕视频网站

标签: 弹幕

上面是“前端如何利用javascript实现弹幕数据循环”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2444.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 首页 > js
Trae:新一代免费的AI编程工具

呱呱工具箱

一款免费的在线小工具,无需下载,打开即可使用!呱呱工具箱

在线育儿补贴计算器

快来看看你到底可以领到多少补贴!生活小工具
上一篇:
下一篇:
x 打工人ai神器