小球点击后抛物线移动

<!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">

    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        #ball {
            display: none;
            width: 10px;
            height: 10px;
            background: red;
            border-radius: 50%;
            position: absolute;
            bottom: 100px;
            right: 100px;
        }
    </style>
</head>

<body>
    <div id="ball"></div>

    <script>
        var ball = document.getElementById('ball');
        document.onclick = function (e) {
            ball.style.top = e.pageY + 'px';
            ball.style.left = e.pageX + 'px';
            ball.style.transition = 'left 1s, top 1s';
            ball.style.display = 'block';
            setTimeout(function () {
                ball.style.top =  '200px';
                ball.style.left = '300px';
                ball.style.transition = 'left 2s linear, top 2s cubic-bezier(0.07, 0.91, 0.53, 1.04)';
            }, 20)
        }
    </script>
</body>

</html>

  

posted @ 2022-03-14 13:14  每天都是鑫的媛  阅读(24)  评论(0)    收藏  举报