当前位置: 首页 > news >正文

js实现弹幕效果

代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>body{background-color: black;}.box{width: 800px;height: 500px;margin: 0 auto;margin-top: 20px;box-shadow: 0px 0px 20px black;overflow: hidden;position: relative;}ul{position: absolute;top: 0;left: 0;width: 800px;height: 400px;margin-top: 30px;}.dm{text-align: center;margin-top: 36px;}li{list-style: none;width: 500px;height: 30px;position: absolute;right: -10px;display: inline-block;z-index: 1;text-shadow: 0px 0px 20px black;}</style>
</head>
<body><div class="box"><video width="800px" height="500px" controls><source src="./vedio/20241022_202302.mp4" type="video/mp4"></video><ul class="send"></ul></div><div class="dm"><input type="text" name="" id=""><button>点击发送弹幕</button><button onclick="yjqp()">一键清屏</button><button onclick="hzdm()">弹幕轰炸</button></div><script>let inp = document.querySelector('input')let btn = document.querySelector('button')let dm = document.querySelector('.dm')let send = document.querySelector('.send')let box = document.querySelector('.box')let ul = document.querySelector('ul')let arr = []let j =0let bsetInterval(()=>{box.style.boxShadow=`0px 0px 20px rgb(${sj()},${sj()},${sj()})`},300)function sj(){return Math.floor(Math.random()*255)}btn.addEventListener('click',()=>{let li = document.createElement('li')li.innerHTML=inp.valuelet i=-520li.style.right=`${++i}px`li.style.textShadow=` 0px 0px 10px rgb(${sj()},${sj()},${sj()})`li.style.marginTop=`${sj()}px`li.style.color=`rgb(${sj()},${sj()},${sj()})`var a=setInterval(()=>{li.style.right=`${++i}px`if(i==400){clearInterval(a)}},8)ul.appendChild(li)})function sj(){let index = Math.floor(Math.random()*340)arr[++j]=indexif(j>10){for(let i=j-10;i<j;i++){if(arr[i]=arr[j]<20){arr[j]=arr[i]break;}}}return arr[j]}//    一键清屏function yjqp(){ul.innerHTML=''clearInterval(b)}// 轰炸弹幕let hz= ['太好看了','绝了','太赞了','666啊','杰瑞真帅','汤姆真美','汤姆666','汤姆吃草']function hzdm(){b=setInterval(()=>{let li = document.createElement('li')li.innerHTML=hz[Math.floor(Math.random()*hz.length)]let i=-520li.style.right=`${++i}px`li.style.textShadow=` 3px 3px 10px rgb(${sj()},${sj()},${sj()})`li.style.marginTop=`${sj()}px`li.style.color=`rgb(${sj()},${sj()},${sj()})`var a=setInterval(()=>{li.style.right=`${++i}px`if(i==800){clearInterval(a)}},8)ul.appendChild(li)// setTimeout(()=>{//     clearInterval(b)// },6000)},100)}</script>
</body>
</html>

效果图:

注:自己放个视频哦


http://www.mrgr.cn/news/56807.html

相关文章:

  • OriginOS 5深度体验:这款新系统,真的有点东西
  • Qt中自定义qDebug打印信息的宏(文件名,行数,函数名,日期,时间等前缀)并取消打印
  • FP独立站搭建指南:如何巧妙应对三大挑战?
  • 深入理解 RabbitMQ 及在.NET 中的应用
  • 数据分析人员需要掌握sql到什么程度?
  • 2024-10-18 学习人工智能的Day10
  • Python 第七节 魔法圆阵
  • leetcode力扣刷题系列——【构成整天的下标对数目 I】
  • [0155].第6节:IDEA常用插件
  • 大模型综述:万字长文详解AI大模型的原理、应用与未来趋势
  • 状态黑板模式
  • 进程间通信大总结Linux
  • 如何学会解决HTTP相关返回值异常?全在这!(上篇)
  • Spring Boot论坛网站:技术要点与案例分析
  • 就是这个样的粗爆,手搓一个计算器:热量计算器
  • springboot高校在线健康咨询服务-计算机设计毕业源码86100
  • css实现外层不换行,内层换行
  • PVE虚拟机强制重启
  • ELK收集nginx日志
  • Stable Diffusion视频插件Ebsynth Utility安装方法
  • S32DS for ARM GPIO实践
  • 基于Spring Boot的论坛网站:从零到部署
  • TensorRT构建的engine文件用途
  • 自动化数据库管理:如何通过存储过程动态创建 MySQL 对象
  • 网盘与移动硬盘优势对比
  • 请求转发和重定向