Skip to content

Commit 40f93aa

Browse files
committed
add ease Elastic and Bounce
1 parent cdcf902 commit 40f93aa

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

examples/simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import QueueAnim from 'rc-queue-anim';
33
import React from 'react';
44
import ReactDom from 'react-dom';
55

6-
ReactDom.render(<QueueAnim>
6+
ReactDom.render(<QueueAnim ease="easeOutElastic" duration={1000}>
77
<div key="1">依次进入</div>
88
<div key="2">依次进入</div>
99
<div key="3">依次进入</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-queue-anim",
3-
"version": "0.11.7",
3+
"version": "0.11.8",
44
"description": "Queue animation component for react",
55
"keywords": [
66
"react",

src/QueueAnim.jsx

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,82 @@ import {
2525
getChildrenFromProps,
2626
} from './utils';
2727
import AnimTypes from './animTypes';
28-
2928
const BackEase = {
3029
easeInBack: [0.6, -0.28, 0.735, 0.045],
3130
easeOutBack: [0.175, 0.885, 0.32, 1.275],
3231
easeInOutBack: [0.68, -0.55, 0.265, 1.55],
3332
};
33+
const _ease = {
34+
easeInElastic: function(_p, o, t) {
35+
let p = _p;
36+
const _p1 = o >= 1 ? o : 1;
37+
const _p2 = (t || 1) / (o < 1 ? o : 1);
38+
const _p3 = _p2 / Math.PI * 2 * (Math.asin(1 / _p1) || 0);
39+
return -(_p1 * Math.pow(2, 10 * (p -= 1)) * Math.sin((p - _p3) * _p2));
40+
},
41+
easeOutElastic: function(p, o, t) {
42+
const _p1 = o >= 1 ? o : 1;
43+
const _p2 = (t || 1) / (o < 1 ? o : 1);
44+
const _p3 = _p2 / Math.PI * 2 * (Math.asin(1 / _p1) || 0);
45+
return _p1 * Math.pow(2, -10 * p) * Math.sin((p - _p3) * _p2) + 1;
46+
},
47+
easeInOutElastic: function(_p, o, t) {
48+
let p = _p;
49+
const _p1 = o >= 1 ? o : 1;
50+
const _p2 = (t || 1) / (o < 1 ? o : 1);
51+
const _p3 = _p2 / Math.PI * 2 * (Math.asin(1 / _p1) || 0);
52+
const a = -0.5 * (_p1 * Math.pow(2, 10 * (p -= 1)) * Math.sin((p - _p3) * _p2));
53+
const b = _p1 * Math.pow(2, -10 * (p -= 1)) * Math.sin((p - _p3) * _p2) * 0.5 + 1;
54+
p *= 2;
55+
return p < 1 ? a : b;
56+
},
57+
easeInBounce: function(_p) {
58+
let p = _p;
59+
const __p = 1 - p;
60+
if (__p < 1 / 2.75) {
61+
return 1 - (7.5625 * p * p);
62+
} else if (p < 2 / 2.75) {
63+
return 1 - (7.5625 * (p -= 1.5 / 2.75) * p + 0.75);
64+
} else if (p < 2.5 / 2.75) {
65+
return 1 - (7.5625 * (p -= 2.25 / 2.75) * p + 0.9375);
66+
}
67+
return 1 - (7.5625 * (p -= 2.625 / 2.75) * p + 0.984375);
68+
},
69+
easeOutBounce: function(_p) {
70+
let p = _p;
71+
if (p < 1 / 2.75) {
72+
return 7.5625 * p * p;
73+
} else if (p < 2 / 2.75) {
74+
return 7.5625 * (p -= 1.5 / 2.75) * p + 0.75;
75+
} else if (p < 2.5 / 2.75) {
76+
return 7.5625 * (p -= 2.25 / 2.75) * p + 0.9375;
77+
}
78+
return 7.5625 * (p -= 2.625 / 2.75) * p + 0.984375;
79+
},
80+
easeInOutBounce: function(_p) {
81+
let p = _p;
82+
const invert = (p < 0.5);
83+
if (invert) {
84+
p = 1 - (p * 2);
85+
} else {
86+
p = (p * 2) - 1;
87+
}
88+
if (p < 1 / 2.75) {
89+
p = 7.5625 * p * p;
90+
} else if (p < 2 / 2.75) {
91+
p = 7.5625 * (p -= 1.5 / 2.75) * p + 0.75;
92+
} else if (p < 2.5 / 2.75) {
93+
p = 7.5625 * (p -= 2.25 / 2.75) * p + 0.9375;
94+
} else {
95+
p = 7.5625 * (p -= 2.625 / 2.75) * p + 0.984375;
96+
}
97+
return invert ? (1 - p) * 0.5 : p * 0.5 + 0.5;
98+
},
99+
};
34100

101+
Object.keys(_ease).forEach(key => {
102+
velocity.Easings[key] = _ease[key];
103+
});
35104
const placeholderKeyPrefix = 'ant-queue-anim-placeholder-';
36105

37106
class QueueAnim extends React.Component {
@@ -182,7 +251,7 @@ class QueueAnim extends React.Component {
182251
performEnterBegin(key, i) {
183252
const childrenShow = this.state.childrenShow;
184253
childrenShow[key] = true;
185-
this.setState({childrenShow}, this.realPerformEnter.bind(this, key, i));
254+
this.setState({ childrenShow }, this.realPerformEnter.bind(this, key, i));
186255
}
187256

188257
realPerformEnter(key, i) {

0 commit comments

Comments
 (0)