Skip to content

Commit

Permalink
add checks before applying any styling
Browse files Browse the repository at this point in the history
  • Loading branch information
hamedbaatour authored and zjffun committed Jul 18, 2020
1 parent 23314bb commit cedebc5
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/Plugins/SwapAnimation/SwapAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,30 @@ export default class SwapAnimation extends AbstractPlugin {
*/
function animate(from, to, {duration, easingFunction, horizontal}) {
for (const element of [from, to]) {
element.style.pointerEvents = 'none';
if (element && element.style) {
element.style.pointerEvents = 'none';
}
}

if (horizontal) {
const width = from.offsetWidth;
from.style.transform = `translate3d(${width}px, 0, 0)`;
to.style.transform = `translate3d(-${width}px, 0, 0)`;
} else {
const height = from.offsetHeight;
from.style.transform = `translate3d(0, ${height}px, 0)`;
to.style.transform = `translate3d(0, -${height}px, 0)`;
if (from && to && from.style && to.style) {
if (horizontal) {
const width = from.offsetWidth;
from.style.transform = `translate3d(${width}px, 0, 0)`;
to.style.transform = `translate3d(-${width}px, 0, 0)`;
} else {
const height = from.offsetHeight;
from.style.transform = `translate3d(0, ${height}px, 0)`;
to.style.transform = `translate3d(0, -${height}px, 0)`;
}
}

requestAnimationFrame(() => {
for (const element of [from, to]) {
element.addEventListener('transitionend', resetElementOnTransitionEnd);
element.style.transition = `transform ${duration}ms ${easingFunction}`;
element.style.transform = '';
if (element && element.style && element.addEventListener) {
element.addEventListener('transitionend', resetElementOnTransitionEnd);
element.style.transition = `transform ${duration}ms ${easingFunction}`;
element.style.transform = '';
}
}
});
}
Expand Down

0 comments on commit cedebc5

Please sign in to comment.