常用动画缓动函数js

在实现过渡效果时需用到缓动函数,不同函数有不同过渡效果。本文整理了部分常用缓动函数,如easeOutCubic、easeInOutQuad等,还附上查看各种缓动函数的网站https://easings.net/zh-cn 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        在实现各种过渡效果过程中不可避免地需要用到缓动函数,不同的缓动函数会实现不同的过渡过程,展现不同的过渡效果。可以很生硬,也可以很柔缓,或是很跳脱。以下是我整理的部分常用缓动函数:

(以下缓动函数均表示由0~1的过渡过程。描述到具体的变化数据时仅需将返回值乘上总变化量即可 : a+(b-a)*t )

再附上一个查看各种缓动函数的网站:https://easings.net/zh-cn

1:easeOutCubic 直入淡出

function easeOutQuad(x) {
   return 1 - (1 - x) * (1 - x);
}

2:easeInOutQuad 淡入淡出

function easeInOutQuad(x){
    return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
}

3:easeInQuad 淡入直出

function easeInQuad(x){
    return x * x;
}

4:easeInBack 欲拒还迎

function easeInBack(x){
    const c1 = 1.70158;
    const c3 = c1 + 1;

    return c3 * x * x * x - c1 * x * x;
}

5:easeOutBack 回光返照

function easeOutBack(x){
    const c1 = 1.70158;
    const c3 = c1 + 1;

    return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
}

6:easeInOutBack 来拒去留

function easeInOutBack(x){
    const c1 = 1.70158;
    const c2 = c1 * 1.525;

    return x < 0.5
      ? (Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
      : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
}

 

7:easeOutBounce 掉落弹跳

function easeOutBounce(x){
    const n1 = 7.5625;
    const d1 = 2.75;

    if (x < 1 / d1) {
        return n1 * x * x;
    } else if (x < 2 / d1) {
        return n1 * (x -= 1.5 / d1) * x + 0.75;
    } else if (x < 2.5 / d1) {
        return n1 * (x -= 2.25 / d1) * x + 0.9375;
    } else {
        return n1 * (x -= 2.625 / d1) * x + 0.984375;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值