CSS3 Keyframe infinite animation/keyframes inside a media query being glitchy - html

I started to make a responsive portfolio for myself and ran into some weird glitch like animations.
My first question is can you put keyframes inside of a media query? or do I need to make two animations and use the media query to switch from one to the other?
If you go to the portfolio => minimize the window to a mobile view => the size of my cloud/bird/waves animations stay as the desktop size and don't change unless you refresh the page.
#media only screen and (max-width: 680px) {
/* Clouds CSS3 animations */
#-webkit-keyframes Clouds-Size {
from {
width: 25%;
}
50% {
width: 30%;
}
to {
width: 25%;
}
}
#-moz-keyframes Clouds-Size {
from {
width: 25%;
}
50% {
width: 30%;
}
to {
width: 25%;
}
}
#-ms-keyframes Clouds-Size {
from {
width: 25%;
}
50% {
width: 30%;
}
to {
width: 25%;
}
}
/* End Clouds CSS3 Animation */
/* Big Wave CSS3 animations */
#-webkit-keyframes Wave-Big-Size {
from {
height: 10em;
}
50% {
height: 9em;
}
to {
height: 10em;
}
}
#-moz-keyframes Wave-Big-Size {
from {
height: 10em;
}
50% {
height: 9em;
}
to {
height: 10em;
}
}
#-ms-keyframes Wave-Big-Size {
from {
height: 10em;
}
50% {
height: 9em;
}
to {
height: 10em;
}
}
/* End Big Wave CSS3 Animation */
}
My second(main) question is an infinite CSS3 keyframe animation seems to glitch after a few seconds like it's having a hard refresh to the animation.
On my portfolio I have two waves that goes from left-right and the other one goes from right-left.
The bottom Big-Wave works like a charm and has a very smooth animation but the smaller top wave seems to do a minor glitch after a few seconds. This isn't life or death to me but is very odd and slightly annoying to me.
Here is the css for this section:
.bigWave {
background: url(../images/bigWave.svg) repeat-x;
height: 7em;
width: 100%;
position: absolute;
bottom: 0;
-webkit-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
-moz-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
-ms-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
-o-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
}
#media only screen and (max-width: 680px) {
.bigWave {
height: 10em;
}
}
.smallWave {
background: url(../images/smallWave.svg) repeat-x;
height: 6em;
width: 100%;
position: absolute;
bottom: 4em;
-webkit-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
-moz-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
-ms-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
-o-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
}
#media only screen and (max-width: 680px) {
.smallWave {
height: 12em;
}
}
Here is the keyframes for the wave animation:
/* Big Wave CSS3 animations */
#-webkit-keyframes Wave-Big {
from {
background-position: 5% 5%
}
to {
background-position: 1300% 0%
}
}
#-webkit-keyframes Wave-Big-Size {
from {
height: 7em;
}
50% {
height: 6em;
}
to {
height: 7em;
}
}
#-moz-keyframes Wave-Big {
from {
background-position: 5% 5%
}
to {
background-position: 1300% 0%
}
}
#-moz-keyframes Wave-Big-Size {
from {
height: 7em;
}
50% {
height: 6em;
}
to {
height: 7em;
}
}
#-ms-keyframes Wave-Big {
from {
background-position: 5% 5%
}
to {
background-position: 1300% 0%
}
}
#-ms-keyframes Wave-Big-Size {
from {
height: 7em;
}
50% {
height: 6em;
}
to {
height: 7em;
}
}
/* End Big Wave CSS3 Animation */
/* Small Wave CSS3 animations */
#-webkit-keyframes Wave-Small {
from {
background-position: 5% 5%
}
to {
background-position: -1300% 0%
}
}
#-webkit-keyframes Wave-Small-Size {
from {
bottom: 4em;
}
50% {
bottom: 3em;
}
to {
bottom: 4em;
}
}
#-moz-keyframes Wave-Small {
from {
background-position: 5% 5%
}
to {
background-position: -1300% 0%
}
}
#-moz-keyframes Wave-Small-Size {
from {
bottom: 4em;
}
50% {
bottom: 3em;
}
to {
bottom: 4em;
}
}
#-ms-keyframes Wave-Small {
from {
background-position: 5% 5%
}
to {
background-position: -1300% 0%
}
}
#-ms-keyframes Wave-Small-Size {
from {
bottom: 4em;
}
50% {
bottom: 3em;
}
to {
bottom: 4em;
}
}
/* End Small Wave CSS3 Animation */
Any ideas or suggestions that you would think may be the culprit?
Any and all help is GREATLY appreciated! This is also my first time with keyframes so tips are welcomed! :]
Portfolio
JSFIDDLE

transform: translate(); is hardware accelerated and should move smoother when animating. For example, the small wave using translateY instead of bottom is less choppy: http://jsfiddle.net/fE9t9/.
/* Small Wave CSS3 animations */
#-webkit-keyframes Wave-Small {
from { background-position: 5% 5% }
to { background-position: -1300% 0% }
}
#-webkit-keyframes Wave-Small-Size {
from, to { -webkit-transform: translateY(0); }
50% { -webkit-transform: translateY(1em); }
}
#-moz-keyframes Wave-Small {
from { background-position: 5% 5% }
to { background-position: -1300% 0% }
}
#-moz-keyframes Wave-Small-Size {
from, to { -moz-transform: translateY(0); }
50% { -moz-transform: translateY(1em); }
}
#-o-keyframes Wave-Small {
from { background-position: 5% 5% }
to { background-position: -1300% 0% }
}
#-o-keyframes Wave-Small-Size {
from, to { -o-transform: translateY(0); }
50% { -o-transform: translateY(1em); }
}
#keyframes Wave-Small {
from { background-position: 5% 5% }
to { background-position: -1300% 0% }
}
#keyframes Wave-Small-Size {
from, to { transform: translateY(0); }
50% { transform: translateY(1em) }
}
/* Big Wave CSS3 animations */
#-webkit-keyframes Wave-Big {
from { background-position: 5% 5% }
to { background-position: 1300% 0% }
}
#-webkit-keyframes Wave-Big-Size {
from, to { -webkit-transform: translateY(0); }
50% { -webkit-transform: translateY(1em); }
}
#-moz-keyframes Wave-Big {
from { background-position: 5% 5% }
to { background-position: 1300% 0% }
}
#-moz-keyframes Wave-Big-Size {
from, to { -moz-transform: translateY(0); }
50% { -moz-transform: translateY(1em); }
}
#-o-keyframes Wave-Big {
from { background-position: 5% 5% }
to { background-position: 1300% 0% }
}
#-o-keyframes Wave-Big-Size {
from, to { -o-transform: translateY(0); }
50% { -o-transform: translateY(1em); }
}
#keyframes Wave-Big {
from { background-position: 5% 5% }
to { background-position: 1300% 0% }
}
#keyframes Wave-Big-Size {
from, to { transform: translateY(0); }
50% { transform: translateY(1em); }
}
Note: animations are only supported IE10+; no version supports the -ms- prefix so it should be taken out.
translate animates slightly quicker; a slight discoordination would be visible if applied to only 1 wave. So translateY should be applied to both waves to make them synchronize. Depending on your preferences, it might be necessary to make some new adjustments to the timing/movement of the waves.

As for the first issue, you can put them where you want but it doesn't work like you hope. It does indeed change the animation itself, but that newly renovated animation is not applied to the elements. You need to use a little js to switch it over to the new one
One way that (should) fix the second problem is to make the animation duration x times larger and making the background position x times larger as well. Example here.
I'd recommend cleaning up your code formatting though, it would make following it easier and perhaps show a hidden issue you're not accounting for

Related

Fliping 3 coin images with CSS

I want to flip a coin with this 3 images, i want that each image could change when its rotating so user cant see the raw changing of each image.. i know that the solution could come with changing the percentages, but cant figure out
Conclusion: I want to "hide" when each coin changes.
This is the HTML and CSS
.coin {
height: 40px;
width: 40px;
animation: spin 18s ease infinite;
border-radius: 50%;
background-size: cover;
}
#keyframes spin {
0% {
-webkit-transform: rotateY(0deg);
background-image: url("https://i.ibb.co/w0M0NjP/3.png");
}
33.33% {
-webkit-transform: rotateY(360deg);
background-image: url("https://i.ibb.co/w0M0NjP/3.png");
}
33.34% {
-webkit-transform: rotateY(0deg);
background-image: url("https://i.ibb.co/n7k3p0X/2.png");
}
66.66% {
-webkit-transform: rotateY(360deg);
background-image: url("https://i.ibb.co/n7k3p0X/2.png");
}
66.67% {
-webkit-transform: rotateY(0deg);
background-image: url("https://i.ibb.co/gmzSqzG/1.png");
}
100% {
-webkit-transform: rotateY(360deg);
background-image: url("https://i.ibb.co/gmzSqzG/1.png");
}
}
<div class="coin"></div>
Consider 2 animations and it will be easier to handle. One for the rotation that will last Xs and the other for the image change that will last (3/2)*Xs with a delay of X/4s because you need to switch on the 90deg angle and 90deg=360deg/4
.coin {
height: 40px;
width: 40px;
animation:
spin 2s linear infinite,
change 3s infinite linear .5s;
border-radius: 50%;
background-size: cover;
}
#keyframes change {
0%,33.33% {
background-image: url("https://i.ibb.co/w0M0NjP/3.png");
}
33.34%,66.66% {
background-image: url("https://i.ibb.co/n7k3p0X/2.png");
}
66.67%,100% {
background-image: url("https://i.ibb.co/gmzSqzG/1.png");
}
}
#keyframes spin {
100% {
transform: rotateY(360deg);
}
}
<div class="coin"></div>
With a variable for better control
.coin {
--x:4s;
height: 40px;
width: 40px;
animation:
spin var(--x) linear infinite,
change calc(3*var(--x)/2) infinite linear calc(var(--x)/4);
border-radius: 50%;
background-size: cover;
}
#keyframes change {
0%,33.33% {
background-image: url("https://i.ibb.co/w0M0NjP/3.png");
}
33.34%,66.66% {
background-image: url("https://i.ibb.co/n7k3p0X/2.png");
}
66.67%,100% {
background-image: url("https://i.ibb.co/gmzSqzG/1.png");
}
}
#keyframes spin {
100% {
transform: rotateY(360deg);
}
}
<div class="coin"></div>

CSS3 Increment Text After Animation Complete

I am new to CSS animations so I made this little project in which there is a box bouncing and it looks pretty real. I want the text inside the box (at the beginning it is just a 0) to increment by one every time the box bounces/the animation is complete. I tried using a counter but it keeps on resetting.
Here is my code:
* {
font-family: sans-serif;
}
#container {
border-bottom: 3px solid #444;
display: flex;
height: 330px;
width: 100%;
}
#oboing {
align-self: flex-end;
animation-duration: 2s;
animation-iteration-count: infinite;
background-color: black;
height: 200px;
margin: 0 auto 0 auto;
transform-origin: bottom;
width: 200px;
}
#counter::before {
color: white;
position: relative;
left: 40%;
top: 40%;
font-size: 50px;
content: counter(bounceCount);
}
#oboing {
animation-name: oboing;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(0.280, 0.840, 0.420, 1);
}
#keyframes oboing {
0% {
transform: scale(1, 1) translateY(0);
counter-reset: bounceCount, calc(counter(bounceCount)+1)
}
10% {
transform: scale(1.1, .9) translateY(0)
}
30% {
transform: scale(.9, 1.1) translateY(-100px);
}
50% {
transform: scale(1.05, .95) translateY(0)
}
57% {
transform: scale(1, 1) translateY(-7px);
}
64% {
transform: scale(1, 1) translateY(0)
}
100% {
transform: scale(1, 1) translateY(0);
counter-increment: bounceCount;
}
}
body {
background: linear-gradient(191deg, #3a22bd, #ea2b0b);
background-size: 400% 400%;
height: 100vh;
overflow: hidden;
-webkit-animation: Colors 4s ease infinite;
-moz-animation: Colors 4s ease infinite;
-o-animation: Colors 4s ease infinite;
animation: Colors 4s ease infinite;
}
#-webkit-keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
#-moz-keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
#-o-keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
#keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
<div id='container'>
<div id='oboing'>
<span id='counter'>0</span>
</div>
</div>
I am open to any suggestions including CSS, HTML, Jquery, JS, etc...
I would also appreciate it if someone could also explain why their code works... Many times I see answers on this website that have only code and no explaining. Please explain!
By it's definition, counter-increment is a non-animatable css property - that's why you're not being successful in using it in your animation. You would have to use a javascript function to count the bounces. As the animation duration is 2 seconds, one approach would be to use a set-interval approach and increment your counter every 2 seconds.
document.getElementById('counter').innerHTML = 0;
function increment() {
var x = document.getElementById('counter').innerHTML;
//if we declare the x value as 0, it will keep resetting,
//so instead, put we retrieve the initial value from the span
//and set the variable to that value
x++;
//increase by 1
document.getElementById('counter').innerHTML = x; //set span value
}
setInterval(increment, 2000); //1000ms in 1 sec
* {
font-family: sans-serif;
}
#container {
border-bottom: 3px solid #444;
display: flex;
height: 330px;
width: 100%;
}
#oboing {
align-self: flex-end;
animation-duration: 2s;
animation-iteration-count: infinite;
background-color: black;
height: 200px;
margin: 0 auto 0 auto;
transform-origin: bottom;
width: 200px;
}
#counter {
color: white;
position: relative;
left: 40%;
top: 40%;
font-size: 50px;
}
#oboing {
animation-name: oboing;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(0.280, 0.840, 0.420, 1);
}
#keyframes oboing {
0% {
transform: scale(1, 1) translateY(0);
}
10% {
transform: scale(1.1, .9) translateY(0)
}
30% {
transform: scale(.9, 1.1) translateY(-100px);
}
50% {
transform: scale(1.05, .95) translateY(0)
}
57% {
transform: scale(1, 1) translateY(-7px);
}
64% {
transform: scale(1, 1) translateY(0)
}
100% {
transform: scale(1, 1) translateY(0);
}
}
body {
background: linear-gradient(191deg, #3a22bd, #ea2b0b);
background-size: 400% 400%;
height: 100vh;
overflow: hidden;
-webkit-animation: Colors 4s ease infinite;
-moz-animation: Colors 4s ease infinite;
-o-animation: Colors 4s ease infinite;
animation: Colors 4s ease infinite;
}
#-webkit-keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
#-moz-keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
#-o-keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
#keyframes Colors {
0% {
background-position: 0% 52%
}
50% {
background-position: 100% 49%
}
100% {
background-position: 0% 52%
}
}
<div id='container'>
<div id='oboing'>
<span id='counter'>0</span>
</div>
</div>
Hope this clears things up for you! :)

How to flicker multiple sets of text one after another

I am mimicking the Windows 10 start up screen. For those of you familiar with the startup, I have the color transitions complete and one set of flickering text ("Hello!"). But I have no idea how to add new sets of text that will flicker following the ("Hello!") Text.
I've tried to research this but have had no success
The final question is how to flicker multiple sets of text one after another
.wrapper {
height: 100%;
width: 100%;
left: 0;
right: 0;
top: 0;
bottom: 0;
position: absolute;
background: linear-gradient(124deg, #0095f0, #e81d1d, #0095f0, #0095f0, #1de840, #ff0000, #f0f0f0, #dd00f3, #009900);
background-size: 1800% 1800%;
-webkit-animation: rainbow 18s ease infinite;
-z-animation: rainbow 25s ease infinite;
-o-animation: rainbow 25s ease infinite;
animation: rainbow 25s ease infinite;
}
#-webkit-keyframes rainbow {
0% {
background-position: 0% 82%
}
50% {
background-position: 100% 19%
}
100% {
background-position: 0% 82%
}
}
#-moz-keyframes rainbow {
0% {
background-position: 0% 82%
}
50% {
background-position: 100% 19%
}
100% {
background-position: 0% 82%
}
}
#-o-keyframes rainbow {
0% {
background-position: 0% 82%
}
50% {
background-position: 100% 19%
}
100% {
background-position: 0% 82%
}
}
#keyframes rainbow {
0% {
background-position: 0% 82%
}
50% {
background-position: 100% 19%
}
100% {
background-position: 0% 82%
}
}
#Message {
color: #ffffff;
margin-top: 250px;
}
#keyframes flickerAnimation {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-o-keyframes flickerAnimation {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-moz-keyframes flickerAnimation {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#-webkit-keyframes flickerAnimation {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.animate-flicker {
-webkit-animation: flickerAnimation 10s infinite;
-moz-animation: flickerAnimation 10s infinite;
-o-animation: flickerAnimation 10s infinite;
animation: flickerAnimation 10s infinite;
color: #ffffff;
margin-top: 250px;
}
#greet {
font-family: roboto;
font-weight: 150;
font-size: 30px;
}
<div class="wrapper">
<div class="animate-flicker" align="center">
<p id="greet">Hello!</h2>
</div>
</div>
I have translated your question in following requirements:
Show several words consecutively at the same spot.
Apply an animation on each word.
My animation displays an element 10 times for a short period of time and hides it again. animation-delay ensures that the animation on the second word starts after the first animation has finished and the animation on the third word starts after the second animation has finished.
To center words I positioned them absolute. This was necessary because I could not integrate display: inline; or display: none; in the keyframe animation (property display is not animatable).
span {
animation-name: flickerAnimation;
animation-duration: 0.1s;
animation-iteration-count: 10;
position: absolute;
opacity: 0;
left: 0;
right: 0;
text-align: center;
}
span:nth-child(2) {
animation-delay: 1s;
}
span:nth-child(3) {
animation-delay: 2s;
}
#keyframes flickerAnimation {
0% {opacity: 1;}
80% {opacity: 1;}
81% {opacity: 0;}
100% {opacity: 0;}
}
<div class="wrapper">
<span>First</span>
<span>Second</span>
<span>Third</span>
</div>

CSS Animation not working when use Media Queries in IE

I use CSS Animation and media queires like this!
HTML
<div class='block'>
<div class='block-bar'></div>
</div>
CSS
.block-bar {
-webkit-animation: timebar 1s infinite;
-moz-animation: timebar 1s infinite;
animation: timebar 1s infinite;
}
#keyframes timebar {
0% { width: 0%; }
99% { width: 100%; }
100% { width: 0%; }
}
#-webkit-keyframes timebar {
0% { width: 0%; }
99% { width: 100%; }
100% { width: 0; }
}
}
it work correctly in Chrome and Firefox but not working in IE
How to fix it? Thank you.
The problem is that IE doesn't like it when keyframes are defined within mediaqueries. If you pull the definition for the keyframes outside the mediaquery it works. (Tested in IE11)
#keyframes timebar {
0% { width: 0%; }
99% { width: 100%; }
100% { width: 0%; }
}
#media(min-width: 300px){
.block-bar {
height: 50px; background-color: red;
-webkit-animation: timebar 1s infinite;
-moz-animation: timebar 1s infinite;
animation: timebar 1s infinite;
}
#-webkit-keyframes timebar {
0% { width: 0%; }
99% { width: 100%; }
100% { width: 0; }
}
}

How to play a second CSS animation once the first one finishes

I'm running into a problem. I'd simply like to, once one CSS3 animation has completed, have my next animation begin (ideally a fade in)
Here's the first animation code:
#truck {
position: absolute;
margin-top:90px;
-moz-animation: slide 4s;
-webkit-animation: slide 4s;
-ms-animation: slide 4s;
animation: slide 4s;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
}
#keyframes slide {
0% { left: 0px; }
35% { left: 250px; }
65% { left: 250px; }
100% { left:590px; }
}
#-webkit-keyframes slide {
0% { left: 0px; }
35% { left: 250px; }
65% { left: 250px; }
100% { left:590px; }
}
#-ms-keyframes slide {
0% { left: 0px; }
35% { left: 250px; }
65% { left: 250px; }
100% { left:590px; }
}
If anyone can help me with the second animation and how to call that once the first one is completed, I would greatly appreciate it.
I think you can use delay:
animation-delay:4s;
-moz-animation-delay:4s; /* Firefox */
-webkit-animation-delay:4s; /* Safari and Chrome */
-o-animation-delay:4s; /* Opera */
(adjust number to fit)