Skip to content

Commit 4d020be

Browse files
committed
Animation easing support custom function (maptalks/maptalks-canvas#2)
1 parent 3e67549 commit 4d020be

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/map/src/core/Animation.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
isNumber,
44
isString,
55
requestAnimFrame,
6-
now
6+
now,
7+
isFunction
78
} from './util';
89
import Point from '../geo/Point';
910
import Coordinate from '../geo/Coordinate';
@@ -443,8 +444,13 @@ const Animation = {
443444
if (!options) {
444445
options = {};
445446
}
446-
let easing = options['easing'] ? Easing[options['easing']] : Easing.linear;
447-
if (!easing) {
447+
let easing;
448+
if (isFunction(options.easing)) {
449+
easing = options['easing'];
450+
} else {
451+
easing = options['easing'] ? Easing[options['easing']] : Easing.linear;
452+
}
453+
if (!easing || !isFunction(easing)) {
448454
easing = Easing.linear;
449455
}
450456
let dStyles, startStyles, destStyles;
@@ -580,7 +586,10 @@ Animation._frameFn = Animation._run.bind(Animation);
580586
const animate = Animation.animate;
581587
export { Animation, Easing, Player, Frame, animate };
582588

583-
export type EasingType = 'outExpo' | 'outQuint' | 'in' | 'out' | 'inAndOut' | 'linear' | 'upAndDown';
589+
/**
590+
* more animation easing functions https://echarts.apache.org/examples/zh/editor.html?c=line-easing
591+
*/
592+
export type EasingType = 'outExpo' | 'outQuint' | 'in' | 'out' | 'inAndOut' | 'linear' | 'upAndDown' | ((t: number) => number);
584593

585594
export type AnimationOptionsType = {
586595
duration?: number;

0 commit comments

Comments
 (0)