Skip to content

Commit f8a2c5f

Browse files
committed
add if
1 parent 568f7df commit f8a2c5f

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/QueueAnim.jsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,14 @@ class QueueAnim extends React.Component {
225225

226226
enterBegin(key, elements) {
227227
elements.forEach((elem) => {
228-
elem.className += (' ' + this.props.animatingClassName[0]);
229-
const currentClassName = this.props.animatingClassName[1];
230-
const reg = new RegExp(currentClassName, 'g');
231-
elem.className = elem.className.replace(reg, '');
228+
const animatingClassName = this.props.animatingClassName;
229+
if (elem.className.indexOf(this.props.animatingClassName[1]) >= 0) {
230+
const reg = new RegExp(animatingClassName[1], 'g');
231+
elem.className = elem.className.replace(reg, '');
232+
}
233+
if (elem.className.indexOf(' ' + animatingClassName[0]) === -1) {
234+
elem.className += (' ' + animatingClassName[0]);
235+
}
232236
});
233237
}
234238

@@ -237,18 +241,22 @@ class QueueAnim extends React.Component {
237241
this.keysAnimating.splice(this.keysAnimating.indexOf(key), 1);
238242
}
239243
elements.forEach((elem) => {
240-
const currentClassName = this.props.animatingClassName[0];
241-
const reg = new RegExp(currentClassName, 'g');
242-
elem.className = elem.className.replace(reg, '').trim();
244+
if (elem.className.indexOf(this.props.animatingClassName[0]) >= 0) {
245+
elem.className = elem.className.replace(this.props.animatingClassName[0], '').trim();
246+
}
243247
});
244248
}
245249

246250
leaveBegin(elements) {
247251
elements.forEach((elem) => {
248-
elem.className += (' ' + this.props.animatingClassName[1]);
249-
const currentClassName = this.props.animatingClassName[0];
250-
const reg = new RegExp(currentClassName, 'g');
251-
elem.className = elem.className.replace(reg, '');
252+
const animatingClassName = this.props.animatingClassName;
253+
if (elem.className.indexOf(animatingClassName[0]) >= 0) {
254+
const reg = new RegExp(animatingClassName[0], 'g');
255+
elem.className = elem.className.replace(reg, '');
256+
}
257+
if (elem.className.indexOf(animatingClassName[1]) === -1) {
258+
elem.className += (' ' + animatingClassName[1]);
259+
}
252260
});
253261
}
254262

@@ -271,9 +279,9 @@ class QueueAnim extends React.Component {
271279
});
272280
}
273281
elements.forEach((elem) => {
274-
const currentClassName = this.props.animatingClassName[1];
275-
const reg = new RegExp(currentClassName, 'g');
276-
elem.className = elem.className.replace(reg, '').trim();
282+
if (elem.className.indexOf(this.props.animatingClassName[1]) >= 0) {
283+
elem.className = elem.className.replace(this.props.animatingClassName[1], '').trim();
284+
}
277285
});
278286
}
279287

0 commit comments

Comments
 (0)