弹幕滚动dd

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #bigbox{
            border: 1px solid black;
            background-color: black;
            height: 500px;
            
        }
        #sb{
            margin-top: 470px;
        }
        #wz{margin-left: 600px;
            color: rgb(25, 26, 26);
            background-color: white;
            
        }
    </style>
</head>
<body>
    <div id="bigbox">
        <div id="sb">
            <input type="text" id="wz" placeholder="发送弹幕捏">
            <button id="btn">发送</button>
        </div>
    </div>
    <script src="./滚动弹幕.js"></script>
</body>
</html>

js

var bigbox = document.querySelector("#bigbox")
var wz = document.querySelector("#wz")
var sb = document.querySelector("#sb")
var btn = document.querySelector("#btn")



btn.onclick = function () {
    // var wz_length=text.length
    // wz_length=random
    var dm = document.createElement("span")
    dm.style.position = "absolute"
    dm.style.top = Math.random() * 500 + "px"
    dm.innerText = wz.value
    dm.style.fontSize = Math.random()*20+10+"px"
    dm.style.color = randomColor()
    bigbox.appendChild(dm)
    var s = 0.9




    var timer = setInterval(
        function () {

            dm.style.left = s * document.body.clientWidth + 'px'
            s -= 0.003
            if (s < 0) {
                clearInterval(timer)
                bigbox.removeChild(dm)
            }
        }, 10)



    function randomColor() {
        // return '#rgb' + '(' + Math.round(Math.random() * 1000) + ',' +
        //     +Math.round(Math.random() * 1000) + ',' + Math.round(Math.random() * 1000) + ')'
        return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
    }




   
    
}






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值