博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
缓动的原理与实现
阅读量:7011 次
发布时间:2019-06-28

本文共 1669 字,大约阅读时间需要 5 分钟。

动画就是以一定的频率去改变元素的属性,使之运动起来,最普通的动画就是匀速的动画,每次增加固定的值。缓动就是用来修改每次增加的值,让其按照不规律的方式增加,实现动画的变化。

程序实现缓动

没有加速度的线性运动

数学公式为:f(x)=x, 代码如下:

AnimationTimer.makeLinear = function () {   return function (percentComplete) {      return percentComplete;   };};

 

逐渐加速的缓入运动

数学公式为:f(x)=x^2, 代码如下:

AnimationTimer.makeEaseIn = function (strength) {   return function (percentComplete) {      return Math.pow(percentComplete, strength*2);   };};

 

逐渐减速的缓出运动

数学公式为:f(x)=1-(1-x)^2, 代码如下:

AnimationTimer.makeEaseOut = function (strength) {   return function (percentComplete) {      return 1 - Math.pow(1 - percentComplete, strength*2);   };};

 

缓入缓出运动

数学公式为:f(x)=x-sin(x*2π)/(2π), 代码如下:

AnimationTimer.makeEaseInOut = function () {   return function (percentComplete) {      return percentComplete - Math.sin(percentComplete*2*Math.PI) / (2*Math.PI);   };};

 

弹簧运动

数学公式为:f(x)=(1-cos(x*Npasses * π) * (1-π))+x, Npassed表示运动物体穿越中轴的次数。 代码如下:

AnimationTimer.makeElastic = function (passes) {   passes = passes || 3;   return function (percentComplete) {       return ((1-Math.cos(percentComplete * Math.PI * passes)) *               (1 - percentComplete)) + percentComplete;   };};

 

弹跳运动

Nbounces表示运动物体被弹起的总次数,弹起的次数为偶数的时候,数学公式为:
f(x)=(1=cos(x Nbounces π) * (1-π))+x
弹起的次数为奇数的时候,数学公式为:
f(x)=2-(((1-cos(x π Nbounces)) * (1-x)+x)
代码如下:
AnimationTimer.makeBounce = function (bounces) {    var fn = AnimationTimer.makeElastic(bounces);        return function (percentComplete) {            percentComplete = fn(percentComplete);            return percentComplete <= 1 ? percentComplete : 2-percentComplete;        };};

 

 

参考资料

posted on
2016-04-07 19:52 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/miid/p/5365110.html

你可能感兴趣的文章
接口自动化测试系列之PHPUnit介绍和环境搭建
查看>>
通过ssl调用远程WebService
查看>>
SQL Server 何时将“脏页”回写到硬盘
查看>>
笔记本电脑的选购之一(2011年10月)
查看>>
电子商务时代必知的PKI及HTTPS
查看>>
程序员教你如何追女生
查看>>
各种测试用例简要模板
查看>>
SCCM 2007 R2部署、操作详解系列之概念篇一:SCCM功能详解
查看>>
Hyper-V 2016 系列教程34 在局域网内架设Windows时间服务器
查看>>
初级运维工程师面试题总结
查看>>
【COCOS2D-X 备注篇】cocos2dx 获取手机截屏等意外取消触屏事件的处理方法!
查看>>
“可穿戴操作系统”,期待吗?
查看>>
买《Python从小白到大牛》专题视频课程,送配套纸质图书
查看>>
Windows Server 2012 R2 WSUS-5:组策略配置自动更新
查看>>
配置SCCM 2012 SP1使用证书
查看>>
观Citrix最新官方发布评测报告有感-外行看热闹,内行看门道
查看>>
完整演示:思科IPS旁路模式的部署
查看>>
K8S集群基于heapster的HPA测试
查看>>
linux服务器集群运维经验
查看>>
Powershell-Lync:如何查询用户使用的语音策略
查看>>