超简单弹幕飘屏

发布于:2023-01-10 ⋅ 阅读:(380) ⋅ 点赞:(0)

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>弹幕飘屏</title>

    <style>

        .aa {

            width: 600px;

            margin: 0 auto;

        }

        #pm {

            width: 600px;

            height: 400px;

            border: 1px solid #5d0b0b;

            position: relative;

            overflow: hidden;

        }

        p {

            position: absolute;

            top: 40px;

            animation: mymate 5s linear 300ms infinite;

        }

        input {

            margin-top: 10px;

            outline: none;

        }

        button {

            margin: 10px;

        }

    </style>

</head>

<body>

    <div class="aa">

        <div id="pm">

        </div>

        <input id="text" type="text" placeholder="输入弹幕">

        <button οnclick="enter()">发送</button>

    </div>

    <script>

        function enter() {

            let text = document.getElementById("text").value;

            let p = document.createElement("p");

            p.innerHTML = text;

            pm.appendChild(p);

            let right =-20;

            let func = function(){

                right++;

                p.style.right = right + 'px'

                if( right > 600){

                    pm.removeChild(p);

                    clearInterval(tiem);

                }

            }

            let tiem = setInterval(func,1)

        }

    </script>

</body>

</html>

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到