Stop line animation in between at center - html

I want this line will move smoothly from right to left but at the center it will stop for 4-5 seconds. Here we can also add some more lines,when first line came to center from right side ,it stops there and wait for another lines and when all lines came at center then all lines stop there for few seconds then again lines start moving in right side. This will continue for infinite loop.
.spinner {
position: relative;
top: 0;
left: 0;
width: 150px;
border: 15px solid transparent;
border-top-color: red;
animation: load 5s infinite ease-in-out;
}
#div {
animation-timing-function: cubic-bezier(0, 1, 1, 1);
}
#keyframes load {
0% {
opacity: 0;
left: 80%;
}
50% {
opacity: 1;
left: 45%;
}
100% {
opacity: 0;
left: 10%;
}
}
<div id="div" class="spinner"></div>

To "hold" the animation for 4 s means it will take 80% of the initial animation duration you defined. So in order to do that, just define the middle keyframe to span from 10% to 90%, leaving equal amount of 10% on both sides:
.spinner {
position: relative;
top: 0;
left: 0;
width: 150px;
border: 15px solid transparent;
border-top-color: red;
animation: load 5s infinite ease-in-out;
}
#div {animation-timing-function: cubic-bezier(0,1,1,1)}
#keyframes load {
0% {
opacity: 0;
left: 80%;
}
10%, 90% {
opacity: 1;
left: 45%;
}
100% {
opacity: 0;
left: 10%;
}
}
<div id="div" class="spinner"></div>

Related

Keyframes Animation has no transition when moving in other direction (Pure CSS)

I have this Keyframe Animation where i move a dot in a square:
* {
margin: 0;
padding: 0;
}
#dot {
height: 10px;
width: 10px;
background: #000;
border-radius: 100%;
position: absolute;
animation: moveDotOne 2s infinite;
transition: all 0.3s;
top: 0;
left: 0;
}
#keyframes moveDotOne {
0% {
top: 0;
}
25% {
top: 20px;
}
50% {
left: 20px;
}
75% {
top: 0;
}
100% {
left: 0;
}
}
<div id="dot"></div>
The only problem is that the 25% keyframe is already running when the 0% isn't even finished. How can i fix that?
Think about what the animation is making it transition the value from.
When it hits 50% it sets left: 20px. So it then transitions from something to 20px. What is that something?
You haven't specified anything. So it is the default value.
You can't transition from auto so it jumps.
Set starting values for left and top in your CSS. Don't assign them only with the animation.
As pointed out you need to think about both x&y positions for the transitions - added variables here to make the effect easier to observe. At each keyframe a x and y position (top,left) are specified.
* {
margin: 0;
padding: 0;
}
:root{
--d:80px;
--w:90px;
}
#box{
padding:1rem;border:1px solid red;
width:var(--w);
height:var(--w);
}
#dot {
height: 10px;
width: 10px;
background: #000;
border-radius: 100%;
position: absolute;
animation: moveDotOne 5s infinite;
transition: all 0.3s;
margin:1rem;
}
#keyframes moveDotOne {
0% {
top:0;
left:0;
}
25% {
top:var(--d);
left:0;
}
50% {
top:var(--d);
left:var(--d);
}
75% {
top:0;
left:var(--d);
}
100%{
top:0;
left:0;
}
}
<div id='box'>
<div id="dot"></div>
</div>

Slideshow animation bug

I have slideshow on my page, but I have small bug in animation and I can't find it.
I use slideshow according to this tutorial: https://www.youtube.com/watch?v=TzAshjkhFQw .
But I want to have only 3 slides not 4.
First 3 slides are ok, but instead of the fourth there is an empty background. I want only 3 slides and after that repeat slideshow.
/* Slider */
.slider {
display: block;
height: 100%;
width: 100%;
z-index: -1;
background-color: #1f1f1f;
overflow: hidden;
position: absolute;
top: 0px;
right: 0px;
border-bottom: 10px solid rgb(121, 0, 0);
}
.slider > * {
position: absolute;
display: block;
width: 100%;
height: 100%;
background-color: #1f1f1f;
animation: slide 12s infinite;
overflow: hidden;
}
.slide:nth-child(1) {
left: 0%;
animation-delay: -1s;
background-image: url(img/slide1.jpg);
background-size: cover;
background-position: center;
}
.slide:nth-child(2) {
left: 100%;
animation-delay: 2s;
background-image: url(img/slide2.png);
background-size: cover;
background-position: center;
}
.slide:nth-child(3) {
left: 100%;
animation-delay: 5s;
background-image: url(img/slide3.jpg);
background-size: cover;
background-position: center;
}
.slide p {
font-size: 2rem;
text-align: center;
display: inline-block;
width: 100%;
margin-top: 340px;
color: #fff;
}
#keyframes slide {
0% { left: 100%; width: 100%; opacity: 1;}
5% { left: 0%;}
25% { left: 0%;}
30% { left: -100%; width: 100%; opacity: 1;}
30.0001% { left: -100%; width: 0%; opacity: 0;}
100% { left: 100%; width: 0%; opacity: 0;}
}
<div class="slider">
<div class="slide">
<p>Slide1</p>
</div>
<div class="slide">
<p>Slide2</p>
</div>
<div class="slide">
<p>Slide3</p>
</div>
</div>
Thank you in advance for your advice!
You need to change the percentages in the animations as well as the timings on the individual slides
#keyframes slide {
0% { left: 100%; width: 100%; opacity: 1;}
6.667% { left: 0%;}
33.334% { left: 0%;}
40% { left: -100%; width: 100%; opacity: 1;}
40.0001% { left: -100%; width: 0%; opacity: 0;}
100% { left: 100%; width: 0%; opacity: 1;}
}
.slide:nth-child(2) {
animation-delay: 3s;
}
.slide:nth-child(3) {
animation-delay: 7s;
}
The animation was initially designed for 4 slides in 12 seconds, i.e. one slide every 3 seconds. If you want to change that to one slide every 4 seconds, you need to space the animations further apart (change the animation delay), and also change the animation so that the slide is visible for a longer time (multiply each percentage by 4/3).
This way of animating slides seems really inflexible however, so you might want to look at some other approach, which allows you to add or remove slides more easily.

Animation and change of two different images

There are two images, first is the boat, second the plane. The desired result is: Boat animates from left to right, at that time the plane is hidden. When the boat reaches the middle of the screen it disappears and the plane appears. This change should happen smoothly.
.image1 {
width: 259px;
height: 259px;
display: block;
position: absolute;
bottom: 135px;
margin: auto;
#include transition(all 1.2s);
background-size: contain;
-webkit-animation: helicopter-move-one 19s linear infinite;
animation: helicopter-move-one 19s linear infinite;
opacity: 1;
}
#-webkit-keyframes helicopter-move-one {
0% {
left: -300px;
}
60% {
opacity: 0;
}
100% {
left: 110%;
}
}
#keyframes helicopter-move-one {
0% {
left: -300px;
display: block;
}
59% {
display: none;
}
60% {
display: none;
}
100% {
left: 110%;
}
}
<div class="outer">
<div class="image1"><img src="" alt="boat"></div>
<div class="image2"><img src="" alt="plane"></div>
</div>
Since I don't have your images I'm using dogs. In this case "The desired result is: adult dog animates from left to right, at that time the puppy is hidden. When adult dog reaches the middle of the screen it disappears and the puppy appears. This change should happen smoothly." Please note that display is not animatable. You need to animate the opacity instead.
img {
width: 150px;
height: 150px;
}
[class ^="image"] {
width: 150px;
height: 150px;
display: block;
position: absolute;
left: 0;
right: 0;
background-size: contain;
}
.image1 {
z-index: 2;
animation: daAnimation1 19s linear infinite;
}
.image2 {
z-index: 1;
margin: auto;
left: 0;
right: 0;
opacity: 0;
animation: daAnimation2 19s linear infinite;
}
#keyframes daAnimation1 {
0% {
left: -150px;
opacity: 1;
}
45% {
left: calc(50vw - 75px);
opacity: 1;
}
50% {
left: calc(50vw - 75px);
opacity: 0;
}
100% {
left: 110%;
opacity: 0;
}
}
#keyframes daAnimation2 {
0% {
opacity: 0;
}
45% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 1;
}
}
<div class="outer">
<div class="image1"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/darwin300.jpg" alt="adult dog"></div>
<div class="image2"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/puppyBeagle300.jpg" alt="puppy"></div>
</div>
I hope this answers your question.
UPDATE:this is an answer to #Danish comment (see below)
img {
width: 150px;
height: 150px;
}
[class ^="image"] {
position:absolute;
background-size: contain;
}
.image1 {
z-index: 2;
opacity: 1;
animation: daAnimation1 19s linear infinite;
}
.image2 {
z-index: 1;
opacity: 1;
}
.outer{
width: 150px;
height: 150px;
display: block;
position: absolute;
animation: OuterAnimation 19s linear infinite;
}
#keyframes OuterAnimation{
0% {
left: -150px;
}
100% {
left: 110%;
}
}
#keyframes daAnimation1 {
0% {
opacity: 1;
}
45% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 0;
}
}
<div class="outer">
<div class="image1"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/darwin300.jpg" alt="adult dog"></div>
<div class="image2"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/puppyBeagle300.jpg" alt="puppy"></div>
</div>

css top property is not working properly on animation

There is an issue with this property, while trying to animate a text, I'm using a text cursor to follow the text but on certain point of the animation this "cursor" (just a line) doesn't do what I put on the code, so... I don't know what is happening to it.
Here you have the piece of code:
.code {
position: relative;
width: 0px;
height: 180px;
animation: coding 1.4s;
animation-fill-mode: forwards;
animation-timing-function: steps(20);
overflow: hidden;
}
#keyframes coding {
0% {
width: 0;
}
100% {
width: 230px;
}
}
.code p {
color: red;
width: 258px;
letter-spacing: 3px;
display: inline-block;
}
.code span {
position: absolute;
top: 10px;
right: 0;
color: red;
animation: cods 7s;
animation-fill-mode: forwards;
font-size: 20px;
}
#keyframes cods {
0% {
opacity: 1;
top: 10px;
right: 0;
}
50% {
top: 10px;
right: 0;
}
75% {
top: 30px;
right: 0;
}
100% {
top: 30px;
left: 0;
}
}
<div class="code">
<p><I am the animated text></p><span>|</span>
</div>
as you see here, the cursor first go to the left and then go to the bottom, but that's not on the code. from 50% to 75% I'm telling: "go 20px down" and then from 75% to 100%: "go left".
Fixed it by changing left: 0 into right: 100% in the 100% keyframe!

avoiding slow motion when using css keyframes

I'm trying to achieve this button animation on hover using only CSS solution :
I've succeed on find a way doing this with css keyframe , but now i'm facing some an unexpected slow motion effect, for now I'm only experimenting this with the top left corner here is what I've done so far :
HTML
<div class="borderTop"></div>
CSS
a {
width: 150px;
height: 50px;
border: 2px solid;
margin: 0 auto;
margin-top: 20%;
display: block;
}
a:hover .borderTop {
width: 10px;
height: 2px;
border-top: 2px solid;
position: relative;
top: -2px;
-webkit-animation: topTheleft 2s alternate;
animation: topTheleft 2s alternate;
}
.borderTop {
width: 10px;
height: 2px;
border-top: 2px solid;
position: relative;
top: -2px;
left: 50px;
}
#-webkit-keyframes topTheleft {
0% { left: -2px; }
50% { left: -30px; }
100% { left: -70px; display: none; }
}
#-o-keyframes topTheleft {
0% { left: -2px; }
50% { left: -30px; }
100% { left: -70px; display: none; }
}
#-moz-keyframes topTheleft {
0% { left: -2px; }
50% { left: -30px; }
100% { left: -70px; display: none; }
}
#keyframes topTheleft {
0% { left: -2px; }
50% { left: -30px; }
100% { left: -70px; display: none; }
}
LIVE DEMO
any help on how to avoid this slow motion on the middle of the animation would be highly appreciated , thank you in advance
edit, is there a way to make the line hide when reach the left: -70px with a transition effect not ansta-hide, any other solution to do it are welcome too
Try getting rid of the 50% lines:
#-webkit-keyframes topTheleft {
0% { left: -2px; }
100% { left: -70px; display: none; }
}
#-o-keyframes topTheleft {
0% { left: -2px; }
100% { left: -70px; display: none; }
}
#-moz-keyframes topTheleft {
0% { left: -2px; }
100% { left: -70px; display: none; }
}
#keyframes topTheleft {
0% { left: -2px; }
100% { left: -70px; display: none; }
}
It looks like the default timing function is ease-in-out : from one animation step to the other, the speed goes slow-fast-slow, to make it look more natural (real physics cannot make an object got from speed 0 to 100 instantaneously).
So what happens is the animation starts slow at 0%, goes fast, then slows down for the 50% step, then accelerates again
Is this what you are looking for ?
https://jsfiddle.net/kvyqyg19/1/
a:hover .borderTop {
/* .. */
-webkit-animation: topTheleft 2s alternate;
animation: topTheleft 2s alternate;
animation-timing-function: linear;
}
#-webkit-keyframes topTheleft {
0% { left: -2px; }
100% { left: -70px; display: none; }
}
/* .. */
I removed the middle (50%) step and set the animation-timing-function: linear;