Skip to content

Commit 52bc9df

Browse files
bugfix sometimes choppy animation
1 parent a927ebb commit 52bc9df

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

example/yarn.lock

+9-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ amdefine@>=0.0.4:
9191
version "1.0.1"
9292
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
9393

94+
animejs@^2.2.0:
95+
version "2.2.0"
96+
resolved "https://registry.yarnpkg.com/animejs/-/animejs-2.2.0.tgz#35eefdfc535b81949c9cb06f0b3e60c02e6fdc80"
97+
9498
ansi-align@^1.1.0:
9599
version "1.1.0"
96100
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-1.1.0.tgz#2f0c1658829739add5ebb15e6b0c6e3423f016ba"
@@ -1353,6 +1357,10 @@ clap@^1.0.9:
13531357
dependencies:
13541358
chalk "^1.1.3"
13551359

1360+
classnames@^2.2.5:
1361+
version "2.2.6"
1362+
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce"
1363+
13561364
13571365
version "4.1.9"
13581366
resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.1.9.tgz#35cee8ae7687a49b98034f70de00c4edd3826301"
@@ -5184,7 +5192,7 @@ querystringify@~1.0.0:
51845192
version "1.0.0"
51855193
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-1.0.0.tgz#6286242112c5b712fa654e526652bf6a13ff05cb"
51865194

5187-
5195+
[email protected], raf@^3.4.0:
51885196
version "3.4.0"
51895197
resolved "https://registry.yarnpkg.com/raf/-/raf-3.4.0.tgz#a28876881b4bc2ca9117d4138163ddb80f781575"
51905198
dependencies:

src/index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export default class ParticleEffectButton extends Component {
5555
progress: 0
5656
}
5757

58+
_rect = {
59+
width: 0,
60+
height: 0
61+
}
62+
5863
componentWillReceiveProps(props) {
5964
if (props.hidden !== this.props.hidden) {
6065
const { status } = this.state
@@ -88,12 +93,14 @@ export default class ParticleEffectButton extends Component {
8893
const canvasStyles = { }
8994

9095
if (status === 'hiding' || status === 'showing') {
91-
const translateProp = this._isHorizontal() ? 'translateX' : 'translateY'
92-
const translateValue = direction === 'left' || direction === 'top'
96+
const prop = this._isHorizontal() ? 'translateX' : 'translateY'
97+
const size = this._isHorizontal() ? this._rect.width : this._rect.height
98+
const value = direction === 'left' || direction === 'top'
9399
? progress : -progress
100+
const px = Math.ceil(size * value / 100)
94101

95-
wrapperStyles.transform = `${translateProp}(${translateValue}%)`
96-
contentStyles.transform = `${translateProp}(${-translateValue}%)`
102+
wrapperStyles.transform = `${prop}(${px}px)`
103+
contentStyles.transform = `${prop}(${-px}px)`
97104
} else if (status === 'hidden') {
98105
wrapperStyles.visibility = 'hidden'
99106
canvasStyles.visibility = 'hidden'
@@ -168,7 +175,6 @@ export default class ParticleEffectButton extends Component {
168175
begin: onBegin,
169176
update: (anim) => {
170177
const value = anim.animatables[0].target.value
171-
172178
setTimeout(() => {
173179
this.setState({ progress: value })
174180
})

0 commit comments

Comments
 (0)