Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I animate absolute positioned element with CSS transition?

I want to animate an element's position change with CSS transition, but it is not working even when I use the transition on all properties, as in the example here: http://jsfiddle.net/yFy5n/3/

However, I don't want my final solution to apply transition to all properties, but instead only on the position change. So the color change should be instant, only the position change from left to right should be animated (the opposite of what is happening now).

like image 568
Digital Ninja Avatar asked Jul 26 '14 16:07

Digital Ninja


People also ask

Can you animate position CSS?

Any CSS property that be transitioned can also be animated. Use animation-delay to pause before executing an animation, using the same time values as for duration. The animation-iteration-count property sets the number of times the animation plays, either as an integer or infinite.

What does the transition CSS property allow you to do?

CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time.

What is the difference between CSS transitions and animations?

CSS transitions are generally best for simple from-to movements, while CSS animations are for more complex series of movements. It's easy to confuse CSS transitions and animations because they let you do similar things. Here are just a few examples: You can visualize property changes.


2 Answers

You forgot to define the default value for left so it doesn't know how to animate.

.test {     left: 0;     transition:left 1s linear; } 

See here: http://jsfiddle.net/shomz/yFy5n/5/

like image 143
Shomz Avatar answered Sep 18 '22 14:09

Shomz


Please Try this code margin-left:60px instead of left:60px

please take a look: http://jsfiddle.net/hbirjand/2LtBh/2/

as @Shomz said,transition must be changed to transition:margin 1s linear; instead of transition:all 1s linear;

like image 32
Hbirjand Avatar answered Sep 18 '22 14:09

Hbirjand