CSS3水平抛物线动画

此生再无相见时 提交于 2019-11-27 02:23:28
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">

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

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


        #ball {
            width: 12px;
            height: 12px;
            background: red;
            border-radius: 50%;
            position: fixed;
            transition: left 1s linear, top 1s ease- in;
        }
    </style>

    <title>
        CSS3水平抛物线动画
    </title>
</head>

<body>

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

    var
        $ball = document.getElementById('ball');
    document.body.onclick = function (evt) {
        console.log(evt.pageX, evt.pageY)
        $ball.style.top = evt.pageY + 'px';
        $ball.style.left = evt.pageX + 'px';
        $ball.style.transition = 'left 0s, top 0s';
        setTimeout(() => {
            $ball.style.top = window.innerHeight-200 + 'px';
            $ball.style.left = '260px';
            $ball.style.transition = 'left 1s linear, top 1s ease-in';
        },
            20
        )
    }
</script>

</html>

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!