Question
let's if i have the following example
A-------------B------------C
how i can start an animation from the middle ( B ) then it go to A then to B and finaly it go to C , i made an example but it's not working good.
Code
.container {
display: block;
}
.container .line {
display: block;
height: 1px;
width: 400px;
background: red;
}
.line:after{
content: "";
height: 20px;
width: 20px;
display: block;
background: black;
border-radius: 50%;
position: absolute;
left: 200px;
top: 0px;
}
#keyframes move {
0% {
left: 200px;
}
25%{
left: 0px;
}
100%{
left: 400px;
}
}
.line:after {
-webkit-animation: move 1s alternate infinite;
-moz-animation: move 1s alternate infinite;
-ms-animation: move 1s alternate infinite;
-o-animation: move 1s alternate infinite;
animation: move 1s alternate infinite;
}
<div class="container">
<div class="line"></div>
</div>
If you do it this way, I thinks it's working well.
In stead of alternate I did use linear. It makes the animation smoother.
.container {
display: block;
}
.container .line {
display: block;
height: 1px;
width: 400px;
background: red;
}
.line:after{
content: "";
height: 20px;
width: 20px;
display: block;
background: black;
border-radius: 50%;
position: absolute;
left: 200px;
top: 0px;
}
#keyframes move {
0% {
left: 200px;
}
25%{
left: 0px;
}
75%{
left: 400px;
}
100%{
left: 200px;
}
}
.line:after {
-webkit-animation: move linear 1s infinite;
-moz-animation: move linear 1s infinite;
-ms-animation: move linear 1s infinite;
-o-animation: move linear 1s infinite;
animation: move linear 1s infinite;
}
<div class="container">
<div class="line"></div>
</div>
You could do it like this, also if add linear (because default is ease) you will get something like this Fiddle
.container .line {
height: 1px;
width: 400px;
background: red;
}
.line:after{
content: "";
height: 20px;
width: 20px;
background: black;
border-radius: 50%;
position: absolute;
left: 200px;
top: 0px;
animation: move 3s infinite;
}
#keyframes move {
0% {left: 200px;}
25%{left: 0px;}
50% {left: 200px;}
75% {left: 400px;}
100%{left: 200px;}
}
<div class="container">
<div class="line"></div>
</div>
Related
I have 2 elements one is rect and another is line. I move rect from left to right once that is done then I rotate line. Then what I want is that once the line is rotated then I want to change the background color of rect.
.rect {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: red;
animation: move 1s;
animation-fill-mode: forwards;
}
.line {
position: absolute;
top: 200px;
left: 100px;
height: 100px;
border-right: 2px solid green;
animation: rotate 1s;
animation-fill-mode: forwards;
animation-delay: 1.3s;
}
#-webkit-keyframes move {
to {
left: 200px;
}
}
#-webkit-keyframes rotate {
to {
transform: rotate(360deg);
}
}
<div class="rect"></div>
<div class="line"></div>
JSFiddle
you can multiple animation separated with comma.
Just add animation delay to second animation which changes the color
.rect {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: red;
animation: move 1s, colorChange 1s 2s;
animation-fill-mode: forwards;
}
.line {
position: absolute;
top: 200px;
left: 100px;
height: 100px;
border-right: 2px solid green;
animation: rotate 1s;
animation-fill-mode: forwards;
animation-delay: 1.3s;
}
#-webkit-keyframes move {
from {}
to {
left: 200px;
}
}
#-webkit-keyframes rotate {
from {}
to {
transform: rotate(360deg);
}
}
#keyframes colorChange {
to {
background-color: green;
}
}
<div class="rect"></div>
<div class="line"></div>
You don't need an additional animation, you just need to adjust the keyframe % and change the duration to 2.3s, which is 1s + 1.3s, if you want the color change to happen simultaneously at the end, if not then adjust the % accordingly:
.rect {
position: absolute;
left: 0;
width: 100px;
height: 100px;
animation: move 2.3s forwards;
}
.line {
position: absolute;
top: 200px;
left: 100px;
height: 100px;
border-right: 2px solid green;
animation: rotate 1s 1.3s forwards;
}
#-webkit-keyframes move {
43.48%, 100% {left: 200px} /* 100% / 2.3 = 43.48% (around), which is 1s duration (like before), then keep it there till the end (100%) */
0%, 99.99% {background: red} /* keep it red 99.99% of the time */
100% {background: blue} /* but not 100% */
}
#-webkit-keyframes rotate {
to {transform: rotate(360deg)}
}
<div class="rect"></div>
<div class="line"></div>
How's this?
In .rect, add a second animation:
.rect {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: red;
animation: move 1s, turnGreen 2.3s;
animation-fill-mode: forwards;
}
Then define the new animation:
#-webkit-keyframes turnGreen{
0% {background: red;}
99% {background: red;}
100% {background: green;}
}
I tested this on your JSFiddle and it seemed to work as you described.
I wanted to make an image of arrow moving so that readers know they can scroll down to read more content. I tried to do that with the animation in CSS but it didn't work.
section.scrollDownContainer {
width: 100%;
position: absolute;
top: 65px;
}
section.scrollDownContainer img {
display: block;
box-shadow: 5px 5px 5px #333333;
margin: auto;
-webkit-animation: arrowmove 0.5s forwards;
-moz-animation: arrowmove 0.5s forwards;
-ms-animation: arrowmove 0.5s forwards;
-o-animation: arrowmove 0.5s forwards;
animation: arrowmove 0.5s forwards;
}
#-webkit-keyframes arrowmove {
0% {
left: 0px;
top: 0px;
}
50% {
left: 0px;
top: 50px;
}
100% {
left: 0px;
top: 0px;
}
}
#-moz-keyframes arrowmove {
0% {
left: 0px;
top: 0px;
}
50% {
left: 0px;
top: 50px;
}
100% {
left: 0px;
top: 0px;
}
}
#-ms-keyframes arrowmove {
0% {
left: 0px;
top: 0px;
}
50% {
left: 0px;
top: 50px;
}
100% {
left: 0px;
top: 0px;
}
}
#-o-keyframes arrowmove {
0% {
left: 0px;
top: 0px;
}
50% {
left: 0px;
top: 50px;
}
100% {
left: 0px;
top: 0px;
}
}
#keyframes arrowmove {
0% {
left: 0px;
top: 0px;
}
50% {
left: 0px;
top: 50px;
}
100% {
left: 0px;
top: 0px;
}
}
<section class="scrollDownContainer">
<img src="./image/arrow.png">
</section>
Can anyone tell me why? Thank you.
You can use transform: translateY(...) in keyframes
section.scrollDownContainer {
width: 100%;
position: absolute;
top: 65px;
}
section.scrollDownContainer img {
display: block;
margin: auto;
animation: arrowmove 0.5s infinite;
}
#keyframes arrowmove {
0% {
transform: translateY(0%);
}
50% {
transform: translateY(50%);
}
100% {
transform: translateY(0%);
}
}
<section class="scrollDownContainer">
<img src="https://upload.wikimedia.org/wikipedia/en/f/f1/Down_Arrow_Icon.png" width="50px" height="50px">
</section>
The left: and top: properties of the animation will have no effect on your image because the image CSS does not contain a position property.
Add position: relative; or position: absolute; to the CSS for the image...
section.scrollDownContainer img {
position: relative; /* <------------------- added */
display: block;
box-shadow: 5px 5px 5px #333333;
margin: auto;
-webkit-animation: arrowmove 0.5s forwards;
-moz-animation: arrowmove 0.5s forwards;
-ms-animation: arrowmove 0.5s forwards;
-o-animation: arrowmove 0.5s forwards;
animation: arrowmove 0.5s forwards;
}
The animation should then function.
Using left:, right:, top:, or bottom: in CSS requires the element to also have a position property.
I'm animating line with css3 from width:0 to width:100%. At the moment is moving from left to right, but I want to make it to start from right to left. Is this posible at all with keyframes?
here is my code
.content {
width: 400px;
height: 200px;
color: white;
cursor: pointer;
text-transform: uppercase;
padding-bottom: 20px;
position: relative;
background: #333;
}
.content .line {
height: 2px;
background: white;
position: absolute;
top: 10px;
-webkit-animation: dude .75s 1 forwards;
-moz-animation: dude .75s 1 forwards;
-o-animation: dude .75s 1 forwards;
animation: dude .75s 1 forwards;
}
#-webkit-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#-moz-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#-o-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
<div class="content">
<div class="line"></div>
</div>
See this FIDDLE
add
.content .line {
right: 0;
}
.content {
width: 400px;
height: 200px;
color: white;
cursor: pointer;
text-transform: uppercase;
padding-bottom: 20px;
position: relative;
background: #333;
}
.content .line {
height: 2px;
background: white;
position: absolute;
top: 10px;
right: 0;
-webkit-animation: dude .75s 1 forwards;
animation: dude .75s 1 forwards;
}
#-webkit-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
<div class="content">
<div class="line"></div>
</div>
Try to animate "left" property instead of width as your element already has position set to absolute.
#keyframes dude {
0% {
left: 100%;
}
100% {
left: 0;
}
}
FIDDLE
change animation-direction to reverse
animation: dude .75s 1 reverse;
I am trying to slide an image across the screen and then stay at a fixed point. I have looked online and found a few variants on what I have but nothing seems to work.
Have a look at this fiddle.
http://jsfiddle.net/lharby/ysgzpuer/
I had to pass in
-webkit-animation: mini 2s normal;
-moz-animation: mini 3s normal;
-o-animation: mini 3s normal;
animation: mini 2s normal;
to the .mini class to animate the div.
Update: This also has the opacity animated:
http://jsfiddle.net/lharby/ysgzpuer/1/
By editing:
#-webkit-keyframes mini {
from {
left:0px;
opacity:0;
}
to{
left:404px;
opacity:1;
}
#-webkit-keyframes mini {
from {
left:-166px;
}
}
.mini {
background-image: url("http://placehold.it/150x150");
position: absolute;
top: 10px;
left: 404px;
width: 166px;
height: 70px;
z-index: 7;
-webkit-animation: mini 2s linear;
}
<div class=mini></div>
Or this if you don't have overflow: hidden on the parent to avoid the scrollbar
#-webkit-keyframes mini {
from {
left:0px;
-webkit-transform: translateX(-166px)
}
}
.mini {
background-image: url("http://placehold.it/150x150");
position: absolute;
top: 10px;
left: 404px;
width: 166px;
height: 70px;
z-index: 7;
-webkit-animation: mini 2s linear;
}
<div class=mini></div>
this will keep the last frame of the animation after its done
animation-fill-mode: forwards;
#-webkit-keyframes mini {
from{
opacity:0;
}
to{
opacity:1;
}
from {
left:0px;
}
to{
left:404px;
}
}
.frame1 {
-webkit-animation: mini 2s normal forwards;
-moz-animation: mini 30s normal forwards;
-o-animation: mini 30s normal forwards;
animation: mini 2s normal forwards;
opacity:1;
}
.mini {
background-image: url("http://blog.grio.com/wp-content/uploads/2012/09/stackoverflow.png");
position: absolute;
top: 10px;
left: -404px;
width: 166px;
height: 70px;
z-index: 7;
}
<div class="frame1 mini">
</div>
hope this is what you are looking for
Html
<div class="stage">
<figure class="ball"></figure>
</div>
CSS
#keyframes slide {
0% {
left: 0;
top: 0;
}
100% {
left: 488px;
top: 0;
}
}
.stage {
background: #eaeaed;
border-radius: 6px;
height: 150px;
position: relative;
min-width: 538px;
}
.stage:hover .ball {
animation-name: slide;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-delay: .5s;
animation-fill-mode: forwards;
}
.stage:active .ball {
animation-play-state: paused;
}
.ball {
background: #2db34a;
border-radius: 50%;
height: 50px;
position: absolute;
width: 50px;
}
Fiddle Demo
.car {
background: url('cartemplate orange 1.png');
width: 444px;
height: 150px;
}
.carleft {
-webkit-animation: moveLeft 3s;
-webkit-animation-delay:2s;
-webkit-animation-iteration-count: infinite;
-moz-animation: moveLeft 3s;
-moz-animation-iteration-count: infinite;
-ms-animation: moveLeft 3s;
-ms-animation-iteration-count: infinite;
-o-animation: moveLeft 3s;
-o-animation-iteration-count: infinite;
animation: moveLeft 3s;
animation-iteration-count: infinite;
}
#-webkit-keyframes moveLeft
{
0% { right: -500px; }
50% { right: 700px; }
100% { right: 2000px; }
}
#-moz-keyframes moveLeft
{
0% { right: -500px; }
50% { right: 700px; }
100% { right: 2000px; }
}
#-ms-keyframes moveLeft
{
0% { right: -500px; }
50% { right: 700px; }
100% { right: 2000px; }
}
#keyframes moveLeft
{
0% { right: -500px; }
50% { right: 700px; }
100% { right: 2000px; }
}
.carright {
-webkit-animation: moveRight 3s;
-webkit-animation-delay:2s;
-webkit-animation-iteration-count: infinite;
-moz-animation: moveRight 3s;
-moz-animation-iteration-count: infinite;
-ms-animation: moveRight 3s;
-ms-animation-iteration-count: infinite;
-o-animation: moveRight 3s;
-o-animation-iteration-count: infinite;
animation: moveRight 3s;
animation-iteration-count: infinite;
}
#-webkit-keyframes moveRight
{
0% { left: -500px; }
50% { left: 700px; }
100% { left: 2000px; }
}
#-moz-keyframes moveRight
{
0% { left: -500px; }
50% { left: 700px; }
100% { left: 2000px; }
}
#-ms-keyframes moveRight
{
0% { left: -500px; }
50% { left: 700px; }
100% { left: 2000px; }
}
#keyframes moveRight
{
0% { left: -500px; }
50% { left: 700px; }
100% { left: 2000px; }
}
.wheel {
width: 50px !important;
height: 50px !important;
position: relative;
}
.wheel1 {
width: 100%;
height: 100%;
background-color: #3D3D3D;
border-radius: 50% / 50%;
position: absolute;
}
.wheel2 {
width: 70%;
height: 70%;
background-color: #B8B8B8;
margin: 10%;
border-radius: 50% / 50%;
position: absolute;
-webkit-animation: wheelActive 800ms;
-webkit-animation-iteration-count: infinite;
-moz-animation: wheelActive 800ms;
-moz-animation-iteration-count: infinite;
-ms-animation: wheelActive 800ms;
-ms-animation-iteration-count: infinite;
-o-animation: wheelActive 800ms;
-o-animation-iteration-count: infinite;
animation: wheelActive 800ms;
animation-iteration-count: infinite;
}
#-webkit-keyframes wheelActive
{
0% { margin: 15%; height: 70%; width: 70%; }
50% { margin: 5%; height: 90%; width: 90%; }
100% { margin: 15%; height: 70%; width: 70%; }
}
#-moz-keyframes wheelActive
{
0% { margin: 15%; height: 70%; width: 70%; }
50% { margin: 5%; height: 90%; width: 90%; }
100% { margin: 15%; height: 70%; width: 70%; }
}
#-ms-keyframes wheelActive
{
0% { margin: 15%; height: 70%; width: 70%; }
50% { margin: 5%; height: 90%; width: 90%; }
100% { margin: 15%; height: 70%; width: 70%; }
}
#keyframes wheelActive
{
0% { margin: 15%; height: 70%; width: 70%; }
50% { margin: 5%; height: 90%; width: 90%; }
100% { margin: 15%; height: 70%; width: 70%; }
}
.wheelleft, .wheelright {
position: absolute;
}
.carleft .wheelleft {
top: 135px;
left: 53px;
}
.carleft .wheelright {
top: 135px;
left: 348px;
}
.carright .wheelleft {
top: 135px;
left: 64px;
}
.carright .wheelright {
top: 135px;
left: 358px;
}
<div class="car carleft">
<div class="wheel wheelleft">
<div class="wheel1"></div>
<div class="wheel2"></div>
</div>
<div class="wheel wheelright">
<div class="wheel1"></div>
<div class="wheel2"></div>
</div>
</div>
jsFiddle: http://jsfiddle.net/c6kBj/
I'm trying to make a car in CSS3 that goes from left to right and also some cars that go from right to left, with different colors and everything fancy. But it isn't working. The wheels are working correctly, but the car is not moving from left to right. Why not?
you are missing position: absolute; on your .car div - without that, .right is meaningless as all elements default to position: static;
.car {
background: url('cartemplate orange 1.png');
width: 444px;
height: 150px;
position: absolute;
}
http://jsfiddle.net/c6kBj/1/
You should actually be using translate(0,0) to move stuff around (performs better than animated position values)