How do you use FLIP animation technique correctly?
up vote
1
down vote
favorite
I am writing a wrapper to animate DOM movement through the FLIP method. FLIP stands for First, Last, Invert, Play. https://aerotwist.com/blog/flip-your-animations/
I am wondering if the FLIP technique is outdated? Or is there something I am missing to get it to work correctly?
As I understand it, the technique goes like this:
- Use getBoundingClientRect to get the initial and final position of the element you want to animate.
- Use CSS transform to move the element back to its initial position.
- Add CSS transition styles to the element.
- Play out the movement by removing the CSS transform from step 2.
FLIP is supposed to optimize movement animation so that every movement is done with requestAnimationFrame and CSS transform, and all animations are under 60fps.
However, I have hit some issues:
Issue #1. Movement is not always under 60fps, so sometimes the animation is jerky.
Issue #2. My animation will not work unless I have two requestAnimationFrames-- one in the invert step and one in the play step. I initially thought I would only need to request one frame in the play step because that's where the animation occurs.
Here's what my code looks like for the invert and play steps:
invert = () => {
changeY = first.top - last.top
changeX = first.left - last.left
requestAnimationFrame(() => {
el.style.transform = `translate(${changeX}px, ${changeY}px)`;
play();
})
}
play = () => {
requestAnimationFrame(() => {
el.classlist.add(animationClass);
el.style.transform = 'none';
el.addEventListener('transitionend', transEnd);
})
}
javascript animation css-animations requestanimationframe
add a comment |
up vote
1
down vote
favorite
I am writing a wrapper to animate DOM movement through the FLIP method. FLIP stands for First, Last, Invert, Play. https://aerotwist.com/blog/flip-your-animations/
I am wondering if the FLIP technique is outdated? Or is there something I am missing to get it to work correctly?
As I understand it, the technique goes like this:
- Use getBoundingClientRect to get the initial and final position of the element you want to animate.
- Use CSS transform to move the element back to its initial position.
- Add CSS transition styles to the element.
- Play out the movement by removing the CSS transform from step 2.
FLIP is supposed to optimize movement animation so that every movement is done with requestAnimationFrame and CSS transform, and all animations are under 60fps.
However, I have hit some issues:
Issue #1. Movement is not always under 60fps, so sometimes the animation is jerky.
Issue #2. My animation will not work unless I have two requestAnimationFrames-- one in the invert step and one in the play step. I initially thought I would only need to request one frame in the play step because that's where the animation occurs.
Here's what my code looks like for the invert and play steps:
invert = () => {
changeY = first.top - last.top
changeX = first.left - last.left
requestAnimationFrame(() => {
el.style.transform = `translate(${changeX}px, ${changeY}px)`;
play();
})
}
play = () => {
requestAnimationFrame(() => {
el.classlist.add(animationClass);
el.style.transform = 'none';
el.addEventListener('transitionend', transEnd);
})
}
javascript animation css-animations requestanimationframe
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am writing a wrapper to animate DOM movement through the FLIP method. FLIP stands for First, Last, Invert, Play. https://aerotwist.com/blog/flip-your-animations/
I am wondering if the FLIP technique is outdated? Or is there something I am missing to get it to work correctly?
As I understand it, the technique goes like this:
- Use getBoundingClientRect to get the initial and final position of the element you want to animate.
- Use CSS transform to move the element back to its initial position.
- Add CSS transition styles to the element.
- Play out the movement by removing the CSS transform from step 2.
FLIP is supposed to optimize movement animation so that every movement is done with requestAnimationFrame and CSS transform, and all animations are under 60fps.
However, I have hit some issues:
Issue #1. Movement is not always under 60fps, so sometimes the animation is jerky.
Issue #2. My animation will not work unless I have two requestAnimationFrames-- one in the invert step and one in the play step. I initially thought I would only need to request one frame in the play step because that's where the animation occurs.
Here's what my code looks like for the invert and play steps:
invert = () => {
changeY = first.top - last.top
changeX = first.left - last.left
requestAnimationFrame(() => {
el.style.transform = `translate(${changeX}px, ${changeY}px)`;
play();
})
}
play = () => {
requestAnimationFrame(() => {
el.classlist.add(animationClass);
el.style.transform = 'none';
el.addEventListener('transitionend', transEnd);
})
}
javascript animation css-animations requestanimationframe
I am writing a wrapper to animate DOM movement through the FLIP method. FLIP stands for First, Last, Invert, Play. https://aerotwist.com/blog/flip-your-animations/
I am wondering if the FLIP technique is outdated? Or is there something I am missing to get it to work correctly?
As I understand it, the technique goes like this:
- Use getBoundingClientRect to get the initial and final position of the element you want to animate.
- Use CSS transform to move the element back to its initial position.
- Add CSS transition styles to the element.
- Play out the movement by removing the CSS transform from step 2.
FLIP is supposed to optimize movement animation so that every movement is done with requestAnimationFrame and CSS transform, and all animations are under 60fps.
However, I have hit some issues:
Issue #1. Movement is not always under 60fps, so sometimes the animation is jerky.
Issue #2. My animation will not work unless I have two requestAnimationFrames-- one in the invert step and one in the play step. I initially thought I would only need to request one frame in the play step because that's where the animation occurs.
Here's what my code looks like for the invert and play steps:
invert = () => {
changeY = first.top - last.top
changeX = first.left - last.left
requestAnimationFrame(() => {
el.style.transform = `translate(${changeX}px, ${changeY}px)`;
play();
})
}
play = () => {
requestAnimationFrame(() => {
el.classlist.add(animationClass);
el.style.transform = 'none';
el.addEventListener('transitionend', transEnd);
})
}
javascript animation css-animations requestanimationframe
javascript animation css-animations requestanimationframe
edited yesterday
asked yesterday
Jeremy Gottfried
124
124
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416559%2fhow-do-you-use-flip-animation-technique-correctly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown