I am creating a keyframe transition sequence. I am wanting the circle to appear for two seconds and then the star to appear for the other two seconds. I am running into a couple of issues.
Why is my star turning into a rectangle at the end of the animation?
How can I get the star to appear from the center rather than the top-left corner sliding in diagonally?
Why does my red circle disappear for a second or two and then the star appear?
Does anyone know what I am doing wrong?
body {
background-color: #F5F5F5;
color: #555;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star {
background-color: #f1c40f;
color: white;
width: 250px;
height: 250px;
margin: 30px auto;
text-align: justify;
-webkit-animation-name: example; /* Chrome, Safari, Opera */
-webkit-animation-duration: 4s; /* Chrome, Safari, Opera */
-webkit-animation-iteration-count: 1 forwards; /* Chrome, Safari, Opera */
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 1 forwards;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes example {
0%, 49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
shape-padding: 10px;
/*transition: all 1s ease; */
-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
}
/* Standard syntax */
#keyframes example {
0%, 49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
shape-padding: 10px;
/* transition: all 1s ease; */
-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
}
}
<div class="star">
</div>
Why is my star turning into a rectangle at the end of the animation?
That's because what probably is a typo error in the below line. You have set forwards to the iteration count property and so the animation-fill-mode takes its default value (which is none). This makes the div.star to snap back to its original shape (the one before start of the animation, a square) once the animation has completed. Removing the forwards from the below line and setting it to the correct property will solve this issue.
animation-iteration-count: 1 forwards;
How can I get the star to appear from the center rather than the top-left corner sliding in diagonally?
Well, getting the star to appear from center (as though its growing) is going to be almost impossible. I will explain the why part a bit later but why the star looks like it is sliding in diagonally is rather simple to explain. The element's initial dimension is 250x250, once the animation starts it is 50x50 and stays that way till 49% of the animation. At 50% no height or width is specified and so the element starts to grow gradually from 50x50 to its original size, which is. 250x250 (this growth will complete at 100%). Since the element has margin: 0 auto, it is always center aligned with respect to the container and so when it grows to its full size, it looks like the top-center point (50%, 0%) point is fixed and element expands towards right, left and bottom. Now this coupled with the clip-path produces the diagonal movement effect.
Snippet showing how the element grows without clip-path:
body {
background-color: #F5F5F5;
color: #555;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star {
background-color: #f1c40f;
color: white;
width: 250px;
height: 250px;
margin: 30px auto;
text-align: justify;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#keyframes example {
0%, 49% {
height: 50px;
width: 50px;
}
50%,
100% {}
}
<div class="star">
</div>
Snippet showing the clip-paths effect at 5 stages during the growth:
Below snippet would make the reason for the slide more clear as you can see how the shape looks at 5 stages during the growth (from 50x50 to 250x250)
body {
background-color: #F5F5F5;
color: #555;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star {
background-color: #f1c40f;
color: white;
margin: 30px auto;
text-align: justify;
-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
}
.dim-50 {
height: 50px;
width: 50px;
}
.dim-100 {
height: 100px;
width: 100px;
}
.dim-150 {
height: 150px;
width: 150px;
}
.dim-200 {
height: 200px;
width: 200px;
}
.dim-250 {
height: 250px;
width: 250px;
}
<div class="star dim-50">
</div>
<div class="star dim-100">
</div>
<div class="star dim-150">
</div>
<div class="star dim-200">
</div>
<div class="star dim-250">
</div>
Why does my red circle disappear for a second or two and then the star appear?
This is partly because of the clip-path and a lack of height and width setting within 50%, 100% keyframe. Since the element is only gradually growing from 50x50 to 250x250 (and it reaches its full size only by the end), the clip-path that you've designed based on original size (250x250) in mind actually starts working only at around 68.75% mark. This is because of the pixel values used in the clip-path. For example, the first point is 125,0 but the element's width is only 50px at 49% and so its width becomes 125px only at 68.75% (200px increase in 50% duration would mean 18.75% time for 75px increase assuming a linear timing function, for ease it'd be a bit longer but you get the point). Because of this, from the 50% mark approximately till the 68.75% mark you get to see nothing.
Another reason for the disappearance can also be attributed to the lack of a clip-path setting in the 0%, 49% keyframes. Because of this, the clip-path of the element is slowly animated from no clip at the start to the actual clip-path at 50% mark.
Solutions:
There are two solutions and they are as follows:
Use your original approach, add height: 250px, width: 250px and border-radius: 0% to the 50%, 100% keyframes. Set a dummy clip-path on the element at 0%, 49% keyframes.
body {
background-color: #F5F5F5;
color: #555;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star {
background-color: #f1c40f;
color: white;
width: 250px;
height: 250px;
margin: 30px auto;
text-align: justify;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#keyframes example {
0%, 49% {
background-color: red;
height: 50px;
width: 50px;
border-radius: 50%;
-webkit-clip-path: polygon(0 0, 50px 0, 50px 50px, 0 50px, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0);
}
50%,
100% {
height: 250px;
width: 250px;
border-radius: 0%;
shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
shape-padding: 10px;
-webkit-clip-path: polygon(125px 0px, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
}
}
<div class="star">
</div>
Set the element's height and width as 250px at the start of the animation itself, use a circular clip-path with 25px radius to produce the circle. This way we can avoid the need for a dummy clip-path. I prefer this approach just because it needs no dummy clip-path.
body {
background-color: #F5F5F5;
color: #555;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star {
background-color: #f1c40f;
color: white;
width: 250px;
height: 250px;
margin: 30px auto;
text-align: justify;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#keyframes example {
0%, 49% {
background-color: red;
height: 250px;
width: 250px;
-webkit-clip-path: circle(25px at center);
}
50%,
100% {
height: 250px;
width: 250px;
shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
shape-padding: 10px;
-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px);
}
}
<div class="star">
</div>
Related
I have a bar chart that uses a gradient background on the bars.
The gradient height is constant and I´m using clip path to show only a portion of the bar. This way, the darkest part is always at 100% height.
The problem I´m having is to animate each bar from 0px height to its given height.
First I tried animating the clip-path using animation, transition and transform. But no luck. Then I tried animating the bar itself using animations - and it kind of works. Only, it goes from top down rather than bottom up. See my fiddle here.
How can I make the bars expand from bottom?
.barChart { clear: both; height: 70px; width: 170px; border-bottom: solid 2px #eee; }
.bar {
float: left;
margin: 4px;
width: 6px;
background: linear-gradient(to top, #8BC2CA 0%, #2E92A0 100%);
animation: expandBar 2s ease;
animation-fill-mode: forwards;
}
.bar1 { clip-path: inset(80% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar2 { clip-path: inset(20% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar3 { clip-path: inset(60% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar4 { clip-path: inset(80% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar5 { clip-path: inset(20% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar6 { clip-path: inset(60% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar7 { clip-path: inset(80% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar8 { clip-path: inset(20% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar9 { clip-path: inset(60% 0 0 0 round 1.5px 1.5px 0px 0px); }
#keyframes expandBar{
0% {
height: 0;
}
100%{
height: 60px;
}
}
<div class="barChart">
<div class="bar bar1"></div>
<div class="bar bar2"></div>
<div class="bar bar3"></div>
<div class="bar bar4"></div>
<div class="bar bar5"></div>
<div class="bar bar6"></div>
<div class="bar bar7"></div>
<div class="bar bar8"></div>
<div class="bar bar9"></div>
</div>
Instead of clip-path you can consider height on your element and a fixed size for your gradient. Then you can easily animate that height.
The trick for the animation is to make the elements inline-block (instead of float) and have a hidden one (set with pseudo-element) that will be height:100% in order to define the baseline at the bottom making your element to animate from bottom and not top.
.barChart {
height: 70px;
width: 170px;
border-bottom: solid 2px #eee;
}
.barChart:before {
content:"";
display:inline-block;
height:100%;
}
.bar {
display:inline-block;
margin: 4px;
width: 6px;
background: linear-gradient(to top, #8BC2CA 0, #2E92A0 70px); /*same as height:100%*/
animation: expandBar 2s ease;
}
.bar1 {height: 80%;}
.bar2 {height: 20%;}
.bar3 {height: 60%;}
.bar4 {height: 70%;}
.bar5 {height: 50%;}
#keyframes expandBar {
0% {
height: 0%;
}
}
<div class="barChart">
<div class="bar bar1"></div>
<div class="bar bar2"></div>
<div class="bar bar3"></div>
<div class="bar bar4"></div>
<div class="bar bar5"></div>
</div>
In case you are intrested you can do this with only one element and multiple background:
.barChart {
height: 70px;
width: 170px;
border-bottom: solid 2px #eee;
--grad:linear-gradient(to top, #8BC2CA 0, #2E92A0 70px);
background-image:var(--grad), var(--grad), var(--grad), var(--grad), var(--grad);
background-size:6px 60%,6px 80%,6px 20%,6px 70%,6px 50%;
background-position:4px 100%, 14px 100%, 26px 100%, 38px 100%,48px 100%;
background-repeat:no-repeat;
animation: expandBar 2s ease;
}
#keyframes expandBar {
0% {
background-size: 6px 0%;
}
}
<div class="barChart">
</div>
I am trying to get a moving border CSS animation to work on a square but I can't quite work out how to get it to work. It works fine on a circle as I just use the rotate transition with the key frames. This is my current markup.
.box {
width: 50px;
height: 50px;
margin: 50px auto;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
position: relative;
-webkit-transition: all 1s ease;
transition: all 1s ease;
}
.box .border {
position: absolute;
top: -4px;
left: -4px;
width: 50px;
height: 50px;
background: transparent;
border: 4px solid transparent;
border-top-color: orangered;
border-radius: 50%;
animation-name: border;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
}
#-webkit-keyframes border {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
<div class="box">
<div class="border"></div>
</div>
The animation in question is using a rotate transform with a stationary border to create the illusion of a moving border whereas it actually is not. With a square, you cannot use a similar model as when we rotate a square it doesn't stay the same like a circle does.
So the available options would be to make use of a SVG stroke-dashoffset based animation like in the below snippet. The stroke-dasharray property provides the length/width of the stroke (1st param) and the length/width of the space (2nd param). The stroke-dashoffset property specifies the offset from the start position at which the stroke should be painted.
polygon {
stroke: red;
stroke-width: 3;
stroke-dasharray: 50, 750;
stroke-dashoffset: 0;
fill: none;
animation: border 5s linear infinite;
}
#keyframes border {
to {
stroke-dashoffset: -800;
}
}
<svg width="210" height="210">
<polygon points="5,5 205,5 205,205 5,205" />
</svg>
If you want a pure CSS solution then you could make use of a linear-gradient based solution like in the below snippet. Here we create four strips of background images based on linear gradients which are of the same thickness of the border. These strips have the color for the required width and is then transparent for the rest. By animating the background-position , we can get something that is close to the effect that we are looking for.
Note that background-position animation works only with fixed pixel values and so the dimensions of the box need be known prior. Everytime the value changes, the background-position values need to be re-configured accordingly.
div {
height: 200px;
width: 200px;
box-sizing: border-box;
background-image: linear-gradient(to right, red 50px, transparent 50px), linear-gradient(to bottom, red 50px, transparent 50px), linear-gradient(to right, red 50px, transparent 50px), linear-gradient(to bottom, red 50px, transparent 50px);
background-size: 100% 3px, 3px 100%, 100% 3px, 3px 100%; /* one of the values is the border thickness, other is 100% */
background-repeat: no-repeat;
background-position: -50px 0px, right -50px, 200px bottom, 0px 200px; /* positions such that none of the images are visible at start */
animation: border 5s linear; /* add infinite if you need infinite animation */
}
#keyframes border {
/* animate position such that they come into view and go out of it one by one */
25% {
background-position: 200px 0px, right -50px, 200px bottom, 0px 200px;
}
50% {
background-position: 200px 0px, right 200px, 200px bottom, 0px 200px;
}
75% {
background-position: 200px 0px, right 200px, -50px bottom, 0px 200px;
}
100% {
background-position: 200px 0px, right 200px, -50px bottom, 0px -50px;
}
}
<div class='border-animation'></div>
If you want a pure CSS solution more closer to the SVG one then we can add more keyframes to the animation like the below snippet.
div {
height: 200px;
width: 200px;
box-sizing: border-box;
background-image: linear-gradient(to right, red 50px, transparent 50px), linear-gradient(to bottom, red 50px, transparent 50px), linear-gradient(to right, red 50px, transparent 50px), linear-gradient(to bottom, red 50px, transparent 50px);
background-size: 100% 3px, 3px 100%, 100% 3px, 3px 100%;
background-repeat: no-repeat;
background-position: -50px 0px, right -50px, 200px bottom, 0px 200px;
animation: border 5s linear;
}
#keyframes border {
20% {
background-position: 150px 0px, right -50px, 200px bottom, 0px 200px;
}
25% {
background-position: 200px 0px, right 0px, 200px bottom, 0px 200px;
}
45% {
background-position: 200px 0px, right 150px, 200px bottom, 0px 200px;
}
50% {
background-position: 200px 0px, right 200px, 150px bottom, 0px 200px;
}
70% {
background-position: 200px 0px, right 200px, 0px bottom, 0px 200px;
}
75% {
background-position: 200px 0px, right 200px, -50px bottom, 0px 150px;
}
95% {
background-position: 200px 0px, right 200px, -50px bottom, 0px 0px;
}
100% {
background-position: 200px 0px, right 200px, -50px bottom, 0px -50px;
}
}
<div class='border-animation'></div>
Here is an even more complete looking infinite animation using pure CSS:
div {
height: 200px;
width: 200px;
box-sizing: border-box;
background-image: linear-gradient(to right, red 50px, transparent 50px), linear-gradient(to bottom, red 50px, transparent 50px), linear-gradient(to right, red 50px, transparent 50px), linear-gradient(to bottom, red 50px, transparent 50px);
background-size: 100% 3px, 3px 100%, 100% 3px, 3px 100%;
background-repeat: no-repeat;
background-position: 0px 0px, right -50px, 200px bottom, 0px 200px;
animation: border 5s linear infinite;
}
#keyframes border {
20% {
background-position: 150px 0px, right -50px, 200px bottom, 0px 200px;
}
25% {
background-position: 200px 0px, right 0px, 200px bottom, 0px 200px;
}
45% {
background-position: 200px 0px, right 150px, 200px bottom, 0px 200px;
}
50% {
background-position: 200px 0px, right 200px, 150px bottom, 0px 200px;
}
70% {
background-position: 200px 0px, right 200px, 0px bottom, 0px 200px;
}
75% {
background-position: 200px 0px, right 200px, -50px bottom, 0px 150px;
}
95% {
background-position: 200px 0px, right 200px, -50px bottom, 0px 0px;
}
95.1% {
background-position: -50px 0px, right 200px, -50px bottom, 0px 0px;
}
100% {
background-position: 0px 0px, right 200px, -50px bottom, 0px -50px;
}
}
<div class='border-animation'></div>
You can pure css3 animated border to accomplish your task by just adding animated-border.min.css file. here is the code snippet.
<a href="ui-box top-leftStart">
<span class='ui-border-element'>
Animated Hyperlink
</span>
</a>
Include this css file : https://cdn.jsdelivr.net/gh/code-fx/Pure-CSS3-Animated-Border#V1.0/css/animated-border/animated-border.min.css
Demo link : https://code-fx.github.io/Pure-CSS3-Animated-Border/
I have created this demo page.
I have created a shape with 5 corners using polygon as shown below.
This is the css needed to make it:
div {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
border: 3px solid black;
border-bottom-left-radius: 15px;
border-top-left-radius: 15px;
}
Unfortunately I cannot get it to add a black border all around the shape (it is missing on the right side). How would I do that?
I have created a fiddle here.
The border property goes around the outside of an element, and the clip-path property applies a mask to an element. So, as far as other CSS rules are concerned, you're still dealing with a rectangle. Because of this, you can't simply apply a border.
It's not impossible to get very close to the effect you want, however. Using (and abusing) CSS pseudo-elements, borders, and filters you can create the same shape plus an outline with only a single HTML div.
div {
position: relative;
width: 210px;
height: 280px;
background: #1e90ff;
border-bottom-left-radius: 15px;
border-top-left-radius: 15px;
filter:
drop-shadow( 0px 3px 0 black)
drop-shadow( 0px -3px 0 black)
drop-shadow( 3px 0px 0 black)
drop-shadow(-3px 0px 0 black);
-webkit-filter:
drop-shadow( 0px 3px 0 black)
drop-shadow( 0px -3px 0 black)
drop-shadow( 3px 0px 0 black)
drop-shadow(-3px 0px 0 black);
}
div::after {
position: absolute;
display: block;
content: '';
width: 0;
height: 0;
left: 210px;
top: 0;
border-left: 70px solid #1e90ff;
border-right: 70px solid transparent;
border-top: 140px solid transparent;
border-bottom: 140px solid transparent;
}
<div>
</div>
So, what's going on here?
The main div element is just the rectangular portion of the shape (with rounded top-left and bottom-left corners). It also has an ::after pseudo-element which creates the triangle shape. The triangle shape is done using the CSS border-triangle hack.
Okay, so that creates the shape without having to mask off any of the element, but a border still can't be applied directly, since I've already (ab)used the border to create the triangle. Using a CSS outline or box-shadow would be the next logical choice, but both properties go all the way around the element's bounding-box... ignoring features like rounded corners or hacky transparent borders.
Enter the CSS filter property. This provides a family of post-processing filters. The important thing to note is that they treat the element as a transparency mask when being applied, rather than respecting the element's bounding-box... and there is a drop-shadow filter!
Unfortunately, it's not quite as flexible as the box-shadow property in that it doesn't have a "spread" parameter which can be used to create solid shapes that are larger than the element. To get around this, we need to cast a drop-shadow in every direction: up, down, right, and left. That's where this monstrosity comes in:
filter:
drop-shadow( 0px 3px 0 black)
drop-shadow( 0px -3px 0 black)
drop-shadow( 3px 0px 0 black)
drop-shadow(-3px 0px 0 black);
Ta-da!
Expanding on this: this works on any shape you can manage to create (as long as it done without clipping). Just apply a drop-shadow filter to the element, or to a parent/wrapper div (if it's a multi-element shape) to get a border.
I'm on a bit of a pseudo kick here, but You can always recreate the element with a black color and throw it behind the original, giving the impression of an outline. Suitable for most purposes, the proposal is demonstrated in this codepen: http://codepen.io/anon/pen/MeJorM
CSS in the codepen has been changed up a bit. Your original is ".orig".
div.orig {
position:relative;
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
border: 1px solid black;
border-bottom-left-radius: 15px;
border-top-left-radius: 15px;
display:block;
}
div.abc {
position:relative;
width: 280px;
height: 280px;
background: #000;
-webkit-clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
border: 1px solid black;
border-bottom-left-radius: 15px;
border-top-left-radius: 15px;
display:block;
}
div.abc div.def{
top:-0.02em;
left:-0.2em;
position:absolute;
display:block;
width: 278px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
clip-path: polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 0 48%, 0% 0%);
border: 1px solid black;
border-bottom-left-radius: 15px;
border-top-left-radius: 15px;
}
I am trying to make a progress bar and using css3 transition to give it a fill effect.
jsfiddle here
When I give it a fixed size, it works as usual, but Problem is when I set the background-size:100% the fill becomes stretch.
How can I create fill effect using background-size:100%?
Progressbar1 is with fixed width and background-size
Progressbar2 is with 100% width and background-size
/* PROGRESS */
.progress {
background-color: #e5e9eb;
height: 0.25em;
position: relative;
width: 24em;
}
.progress-bar {
animation-duration: 3s;
animation-name: width;
background-image: repeating-linear-gradient(to right, transparent, #000 50px, #fff 100px, transparent 150px);
background-size: 24em 0.25em;
height: 100%;
position: relative;
width:100%
}
.progress2 {
background-color: #e5e9eb;
height: 0.25em;
position: relative;
width: 100%;
}
.progress-bar2 {
animation-duration: 3s;
animation-name: width;
background-image: repeating-linear-gradient(to right, transparent, #000 50px, #fff 100px, transparent 150px);
background-size: 100% 0.25em;
height: 100%;
position: relative;
width:100%
}
/* ANIMATIONS */
#keyframes width {
0%, 100% {
transition-timing-function: cubic-bezier(1, 0, 0.65, 0.85);
}
0% {
width: 0%;
}
100% {
width: 100%;
}
}
<div class="progress">
<div class="progress-bar">
</div>
</div>
<br>
<div class="progress2">
<div class="progress-bar2">
</div>
</div>
I am having a tough time figuring out why my image within my keyframe (of the star) is showing up before the 50% keyframe. Right now it is showing up almost immediately.
What can I do to make it show up when I am wanting it to (after 50%)?
body {
background-color: #F5F5F5;
color: #555;
height: 100vh;
width: 100%;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star-container {
background-color: green;
color: white;
width: 60%;
height: 80%;
margin: 10% auto;
text-align: justify;
position: relative;
}
.star {
width: 250px;
height: 250px;
text-align: justify;
-webkit-animation-name: star;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
animation-name: star;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
}
22%,
45% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
/*shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );
shape-padding: 10px;
/*transition: all 1s ease; */
/*-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );*/
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
/* Standard syntax */
#keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
}
22%,
45% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
/*shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );
shape-padding: 10px;
/*transition: all 1s ease; */
/*-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );*/
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
}
<div class="star-container">
<div class="star">
</div>
</div>
Reason:
As I had mentioned in my reply to your comment here, the problem is because there is no background image specified in any of the frames before the 50% keyframe. This means that the UA treats it like a gradual change of background image from 0% to 50%. But since there cannot be a intermediate state for image display, it appears at roughly half duration between 0% to 50% for an animation with linear timing function (for other timing functions like ease, ease-in, ease-out it would be a little before or after the mid way point but the logic is the same).
Demo as proof of above point:
In the below snippet, I have set the animation-timing-function to linear and have inserted frames to change the background-color to yellow at 25% mark. You'd see how the image now appears at the exact same time when the color changes to yellow. This is to prove the statement in first para.
body {
background-color: #F5F5F5;
color: #555;
height: 100vh;
width: 100%;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star-container {
background-color: green;
color: white;
width: 60%;
height: 80%;
margin: 10% auto;
text-align: justify;
position: relative;
}
.star {
width: 250px;
height: 250px;
text-align: justify;
-webkit-animation-name: star;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
animation-name: star;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
animation-timing-function: linear;
}
#keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
}
22% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
25% {
background-color: yellow;
}
45% {
background-color: yellow;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
49% {
background-color: yellow;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
/*shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );
shape-padding: 10px;
/*transition: all 1s ease; */
/*-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );*/
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
}
<div class="star-container">
<div class="star">
</div>
</div>
Solution:
The fix to this problem is to set background-image to none in all the frames before the 50% mark.
Demo: (Have removed all the vendor-prefixed versions to keep the snippet small)
body {
background-color: #F5F5F5;
color: #555;
height: 100vh;
width: 100%;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star-container {
background-color: green;
color: white;
width: 60%;
height: 80%;
margin: 10% auto;
text-align: justify;
position: relative;
}
.star {
width: 250px;
height: 250px;
text-align: justify;
animation-name: star;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
background-image: none;
}
22%, 45% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
background-image: none;
}
49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
background-image: none;
}
50%,
100% {
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
}
<div class="star-container">
<div class="star">
</div>
</div>
Add animation-timing-function: linear to .star this will show the image exactly after 2s.