very easy 的抛物线动画

抛前

抛过程中


抛完


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>抛物线动画</title>
    <link rel="stylesheet" href="parabola.css" />    
<style>
.animation-box {
    width: 80%;
    margin: 20px auto;
}
.top-box,
.bottom-box {
    display: flex;
    justify-content: space-between;
}
.top-box>div,
.bottom-box>div {
    width: 20px;
    height: 20px;
    border-radius: 10px;
    background: plum;
    position: relative;
    transition: left 1s linear, top 1s ease-in;
}
.center-box {
    width: 100%;
    height: 500px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.center-middle-box {
    width: 20px;
    height: 20px;
    border-radius: 10px;
    background: pink;
}
</style>
</head>

<body>
    <div class="animation-box">
        <div class="top-box">
            <div class="left-top-box" id='left-top-box-id' onclick="startAnimation('left-top-box-id')"></div>
            <div class="right-top-box" id="right-top-box-id" onclick="startAnimation('right-top-box-id')"></div>
        </div>
        <div class="center-box">
            <div class="center-middle-box" id="center-middle-box-id"> </div>
        </div>
        <div class="bottom-box">
            <div class="left-bottom-box" id="left-bottom-box-id" onclick="startAnimation('left-bottom-box-id')"></div>
            <div class="right-bottom-box" id="right-bottom-box-id" onclick="startAnimation('right-bottom-box-id')">
            </div>
        </div>
    </div>
</body>
<script>

    function startAnimation(startId, endId = 'center-middle-box-id', xPoint = 'left', yPoint = 'top') {
        const start = document.getElementById(startId)
        const end = document.getElementById(endId)
        const startx = start.offsetLeft
        const starty = start.offsetTop
        const endx = end.offsetLeft
        const endy = end.offsetTop
        const x = endx - startx
        const y = endy - starty
        start.style.top = '0px';
        start.style.left = '0px';
        start.style.background = 'aquamarine'
        start.style.transition = `${xPoint} 0s, ${yPoint} 0s `;
        setTimeout(() => {
            start.style.top = y + 'px';
            start.style.left = x + 'px';
            start.style.transition = `${xPoint} 1s linear, ${yPoint} 1s ease-in`;
        }, 10);
    }


</script>

</html>


复制代码


转载于:https://juejin.im/post/5cf75cf3f265da1bce3dbeb9

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值