Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth CSS transform animations

I'm looking at optimising CSS animations for performance.

From what I can find out using

.item { transform: translate(-25px,-50px)

is much more efficient than

.item { left: -25px; top: -50px }

I've setup a little animation that move and rotates a box .balloon which as multiple steps to the animation. The problem is though the animation becomes very jerky, even with positioning ans rotation declared for each step

Here is my standard CSS

@keyframes balloon {
    0%,100% { left:809px; top:50px; transform: rotate(0deg) }
    10% { transform: rotate(-9deg) }
    25%,75% { top:25px }
    50% { left:235px;top:75px }
    45% { transform: rotate(3deg) }
    75% { transform: rotate(12deg) }
}

This is my optimised CSS, which is where the jerky animation comes in to effect

@keyframes balloon {
    0% { transform: translate(0,0) rotate(0deg) }
    10% { transform: translate(-57.5px,-10px) rotate(-9deg) }
    25% { transform: translate(-143.75px,-25px) rotate(-4deg) }
    45% { transform: translate(-517.5px,22.5px) rotate(3deg) }
    50% { transform: translate(-575px,25px) rotate(4.5deg) }
    75% { transform: translate(-287.5px,-25px) rotate(12deg) }
    100% { transform: translate(0,0) rotate(0deg) }
}

Is there an alternative solution for this?

I've put a CodePen together here.

like image 331
Matt Avatar asked May 01 '14 13:05

Matt


People also ask

How do I make my animation smoother in CSS?

The speed curve defines the TIME an animation uses to change from one set of CSS styles to another. The speed curve is used to make the changes smoothly.

How do I make my animations smoother?

Use Squash & Stretch to Avoid Stiff Movement It can also give the viewer information about how hard or soft the object is (softer objects should squash and stretch more). If your animations are looking too rigid, try adding squash and stretch to the movement and see how that improves things.

Can you animate transform CSS?

Animating your Transforms If you think that's cool, realise that CSS Animation can be applied not just to the transforms, but also to other CSS properties including: opacity, colour and a bunch of others.


1 Answers

In your animation-property, try to add a value for the animation-timing-function

Something like

animation: balloon 15s infinite linear;

would make it more smooth.

like image 77
tobi Avatar answered Oct 08 '22 10:10

tobi