For some reason the svg icon in this css animation is flickering sometimes on Chromium based Browsers. On Safari and Firefox it works flawlessly. How can I fix that? Has something to do with transform: translate? I've also tried to paste -webkit-transform:translate3d(0,0,0); which should solve the problem but unfortunately it didn't.
body {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.u-loading {
width: 128px;
height: 128px;
display: block;
margin: 48px;
}
.u-loading__symbol {
background-color: #4caf50;
padding: 8px;
animation: loading 3s infinite;
border-radius: 5px;
}
.u-loading__symbol img {
display: block;
max-width: 100%;
animation: loading-icon 3s infinite;
}
#keyframes loading {
0% {
transform: perspective(250px) rotateX(0deg) rotateY(0deg);
}
15% {
background-color: #4caf50;
}
16% {
background-color: #b44646;
}
50% {
transform: perspective(250px) rotateX(180deg) rotateY(0deg);
background-color: #b44646;
}
65% {
background-color: #b44646;
}
66% {
background-color: #4caf50;
}
100% {
transform: perspective(250px) rotateX(180deg) rotateY(-180deg);
}
}
#keyframes loading-icon {
0% {
transform: perspective(250px) rotateX(0deg) rotateY(0deg);
}
15% {
transform: perspective(250px) rotateX(0deg) rotateY(0deg);
}
16% {
transform: perspective(250px) rotateX(180deg) rotateY(0deg);
}
50% {
transform: perspective(250px) rotateX(180deg) rotateY(0deg);
}
65% {
transform: perspective(250px) rotateX(180deg) rotateY(0deg);
}
66% {
transform: perspective(250px) rotateX(180deg) rotateY(180deg);
}
100% {
transform: perspective(250px) rotateX(180deg) rotateY(180deg);
}
}
<div class="u-loading">
<div class="u-loading__symbol">
<img src="https://kaiser.kiwi/assets/kaiserkiwi-logo.svg">
</div>
</div>
Thank's in advance
I'm looking at your example in Chrome and the animation looks pretty slick. The only "flicker" I see is a brief glimpse of the back of the red div's image at the very end of it's transition. I think this can be solved by using backface-visibility: hidden; on the element you are transforming to flip over.
See: https://developer.mozilla.org/en-US/docs/Web/CSS/backface-visibility
Related
I'm trying to use CSS animations to animate a cube rotating, and pausing on each face for a set amount of time.
Pen here
#keyframes frontToLeft {
75% { transform: rotateY(0); }
100% { transform: rotateY(90deg); }
}
#keyframes leftToBack {
75% { transform: rotateY(90deg); }
100% { transform: rotateY(180deg); }
}
#keyframes backToRight {
75% { transform: rotateY(180deg); }
100% { transform: rotateY(270deg); }
}
#keyframes rightToFront {
75% { transform: rotateY(270deg); }
100% { transform: rotateY(360deg); }
}
.cube-container {
padding-top: 200px;
perspective: 800px;
perspective-origin: 50% 100px;
}
.qube {
position: relative;
width: 200px;
margin: 0 auto;
transform-style: preserve-3d;
animation-name: frontToLeft, leftToBack, backToRight, rightToFront;
animation-timing-function: linear;
animation-fill-mode: forwards;
animation-duration: 2s, 2s, 2s, 2s;
animation-delay: 2s, 4s, 6s, 8s;
* {
position: absolute;
left: 0;
top: 0;
margin: 0;
padding: 0;
width: 200px;
height: 200px;
background: rgba(255,255,255,0.1);
box-shadow: inset 0 0 30px rgba(125,125,125,0.8);
}
.front {
transform: translateZ(100px);
}
.back {
transform: translateZ(-100px) rotateY(180deg);
}
.top {
transform: rotateX(-90deg) translateY(-100px);
transform-origin: top center;
}
.bottom {
transform: rotateX(90deg) translateY(100px);
transform-origin: bottom center;
}
.left {
transform: rotateY(270deg) translateX(-100px);
transform-origin: center left;
}
.right {
transform: rotateY(-270deg) translateX(100px);
transform-origin: top right;
}
}
<div class="cube-container">
<div class="qube">
<div class="front">front</div>
<div class="left">left</div>
<div class="back">back</div>
<div class="right">right</div>
<div class="top">top</div>
<div class="bottom">bottom</div>
</div>
</div>
In Google Chrome and Edge, the animation seems to glitch, but in Firefox it works as intended.
I'd like the outcome to be:
Front Face - Pause 2 seconds, rotate 2 seconds
Left Face - Pause 2 seconds, rotate 2 seconds
Back Face - Pause 2 seconds, rotate 2 seconds
Right Face - Pause 2 seconds, rotate 2 seconds
Can anyone see where this would be going wrong? I have the Codepen preprocessing SCSS with prefixes.
Thanks in advance!
From what I can tell testing this it looks like a bug. Nothing I've tried seems to work to correct the animation. Like you say, Firefox works as expected.
All I can think of as a potential fix is to combine it into one animation something like this:
#keyframes spinCube {
20% { transform: rotateY(0deg); }
25% { transform: rotateY(90deg); }
45% { transform: rotateY(90deg); }
50% { transform: rotateY(180deg); }
70% { transform: rotateY(180deg); }
75% { transform: rotateY(270deg); }
95% { transform: rotateY(270deg); }
100% { transform: rotateY(360deg); }
}
.qube {
animation: spinCube 8s 1 forwards;
}
It would take a bit of tweaking to get the timing right, but it's the only thing I can think of.
Here's a CodePen Example of this alternative solution.
The Code attached consists of an animation CSS box with a <p>. It's working but the problem is that, why is it not vertical aligned? I will need to use flex function: "align-items = center" to make it aligned.
.LoaderBox {
width: 100%;
border: 1px solid rgba(255, 0, 0, 1.00);
display: flex;
justify-content: center;
}
.LoaderBox>p {
color: rgba(106, 106, 106, 1.00);
font-size: 15px;
margin-left: 20px;
display: block;
}
.LoaderBox_spinner {
width: 20px;
height: 20px;
background-color: #333;
-webkit-animation: sk-rotateplane 1.2s infinite ease-in-out;
animation: sk-rotateplane 1.2s infinite ease-in-out;
display: block;
}
#-webkit-keyframes sk-rotateplane {
0% {
-webkit-transform: perspective(120px)
}
50% {
-webkit-transform: perspective(120px) rotateY(180deg)
}
100% {
-webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg)
}
}
#keyframes sk-rotateplane {
0% {
transform: perspective(120px) rotateX(0deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg)
}
50% {
transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg)
}
100% {
transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
-webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
}
}
<div class="LoaderBox">
<div class="LoaderBox_spinner"></div>
<p>Verifying</p>
</div>
Just add align-items: center to your flex-container .LoaderBox.
By default all items are stretched (align-items: stretch).
p has equal vertical margins by default (margin-top and margin-bottom), and div doesn't. So in this case p determines flex-container's height. And also looks like it's centered vertically.
Demo:
.LoaderBox {
width: 100%;
border: 1px solid rgba(255, 0, 0, 1.00);
display: flex;
align-items: center; /* new */
justify-content: center;
}
.LoaderBox>p {
color: rgba(106, 106, 106, 1.00);
font-size: 15px;
margin-left: 20px;
display: block;
}
.LoaderBox_spinner {
width: 20px;
height: 20px;
background-color: #333;
-webkit-animation: sk-rotateplane 1.2s infinite ease-in-out;
animation: sk-rotateplane 1.2s infinite ease-in-out;
display: block;
}
#-webkit-keyframes sk-rotateplane {
0% {
-webkit-transform: perspective(120px)
}
50% {
-webkit-transform: perspective(120px) rotateY(180deg)
}
100% {
-webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg)
}
}
#keyframes sk-rotateplane {
0% {
transform: perspective(120px) rotateX(0deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg)
}
50% {
transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg)
}
100% {
transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
-webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
}
}
<div class="LoaderBox">
<div class="LoaderBox_spinner"></div>
<p>Verifying</p>
</div>
.LoaderBox {
width: 100%;
border: 1px solid rgba(255, 0, 0, 1.00);
display: flex;
justify-content: center;
padding:20px;
box-sizing:border-box;
}
.LoaderBox>p {
color: rgba(106, 106, 106, 1.00);
font-size: 15px;
display: block;
padding:0px;
margin:0px;
margin-left:20px;
}
.LoaderBox_spinner {
width: 20px;
height: 20px;
background-color: #333;
-webkit-animation: sk-rotateplane 1.2s infinite ease-in-out;
animation: sk-rotateplane 1.2s infinite ease-in-out;
display: block;
float:left;
}
#-webkit-keyframes sk-rotateplane {
0% {
-webkit-transform: perspective(120px)
}
50% {
-webkit-transform: perspective(120px) rotateY(180deg)
}
100% {
-webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg)
}
}
#keyframes sk-rotateplane {
0% {
transform: perspective(120px) rotateX(0deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg)
}
50% {
transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg)
}
100% {
transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
-webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
}
}
p{ float:left;}
<div class="LoaderBox">
<div class="LoaderBox_spinner"></div>
<p>Verifying</p>
</div>
I successfully created a cube in a cube, a Tesseract. But for some reason I really can't explain, the cube is moving downwards while the Animation is going on.
If you watch the scrolling bar of your browser, the entire cube is moving downwards.
And yes, of course you can "ignore" this problem by changing the margin of the parent-div-element but that doesn't solve it.
#-webkit-keyframes cube-spin {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(360deg);
transform: rotateY(360deg);
}
}
#keyframes cube-spin {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(360deg);
transform: rotateY(360deg);
}
}
#-webkit-keyframes counter-rot {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(-360deg);
transform: rotateY(-360deg);
}
}
#keyframes counter-rot {
from {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(-360deg);
transform: rotateY(-360deg);
}
}
.cube-wrap {
-webkit-perspective: 800px;
perspective: 800px;
-webkit-perspective-origin: 50% 0%;
perspective-origin: 50% 0%;
}
.outer {
width: 300px !important;
}
.cube {
position: relative;
width: 200px;
margin: 0 auto;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-animation: cube-spin 8s infinite linear;
animation: cube-spin 8s infinite linear;
}
.backendtext {
position: absolute;
width: 200px;
font-size: 35px;
text-align: center;
font-family: sans-serif;
text-transform: uppercase;
-webkit-animation: counter-rot 8s infinite linear;
animation: counter-rot 8s infinite linear;
}
.outer div {
width: 300px;
height: 300px;
background: rgba(255, 116, 0, 0.1);
line-height: 530px;
}
.inner div {
width: 200px;
height: 200px;
background: rgba(153, 69, 0, 0.7);
}
.cube div {
position: absolute;
box-shadow: inset 0 0 30px rgba(125,125,125,0.8);
font-size: 35px;
text-align: center;
font-family: sans-serif;
text-transform: uppercase;
}
.depth div.front-pane {
-webkit-transform: translateY(-100px) translateZ(100px);
transform: translateY(-100px) translateZ(100px);
}
.outer.depth div.front-pane {
-webkit-transform: translateY(-150px) translateZ(150px);
transform: translateY(-150px) translateZ(150px);
}
.depth div.back-pane {
-webkit-transform: translateY(-100px) translateZ(-100px) rotateY(180deg);
transform: translateY(-100px) translateZ(-100px) rotateY(180deg);
}
.outer.depth div.back-pane {
-webkit-transform: translateY(-150px) translateZ(-150px) rotateY(180deg);
transform: translateY(-150px) translateZ(-150px) rotateY(180deg);
}
.depth div.left-pane {
-webkit-transform: translateY(-100px) translateX(100px) rotateY(-270deg);
transform: translateY(-100px) translateX(100px) rotateY(-270deg);
}
.outer.depth div.left-pane {
-webkit-transform: translateY(-150px) translateX(150px) rotateY(-270deg);
transform: translateY(-150px) translateX(150px) rotateY(-270deg);
}
.depth div.right-pane {
-webkit-transform: translateY(-100px) translateX(-100px) rotateY(270deg);
transform: translateY(-100px) translateX(-100px) rotateY(270deg);
}
.outer.depth div.right-pane {
-webkit-transform: translateY(-150px) translateX(-150px) rotateY(270deg);
transform: translateY(-150px) translateX(-150px) rotateY(270deg);
}
.depth div.top-pane {
-webkit-transform: translateY(-200px) rotateX(-90deg);
transform: translateY(-200px) rotateX(-90deg);
}
.outer.depth div.top-pane {
-webkit-transform: translateY(-300px) rotateX(-90deg);
transform: translateY(-300px) rotateX(-90deg);
}
.depth div.bottom-pane {
-webkit-transform: rotateX(90deg);
transform: rotateX(90deg);
}
<div style="height: 300px; margin-top: 400px;">
<div class="cube-wrap">
<div class="cube depth inner">
<a class="backendtext">Backend</a>
<div class="front-pane"></div>
<div class="back-pane"></div>
<div class="top-pane"></div>
<div class="bottom-pane"></div>
<div class="left-pane"></div>
<div class="right-pane"></div>
</div>
<div class="cube depth outer">
<div class="front-pane">Frontend</div>
<div class="back-pane">Frontend</div>
<div class="top-pane"></div>
<div class="bottom-pane"></div>
<div class="left-pane">Frontend</div>
<div class="right-pane">Frontend</div>
</div>
</div>
//EDIT: Works fine on Chrome and Edge. Will try to add prefixes to everything and see if it solves the problem.
//EDIT2: Added Prefixes, still doesn't work on Firefox but does properly on Chrome, Edge etc.
//EDIT3: Set Overflow of the cube-wrapper to hidden but I would still love to know the reason.
I am trying to learn CSS3 by making a simple image slider using animations.
I have successfully achieved the animation pattern to my needs by doing some calculation but the problem is the subsequent images are not following the same rule which is a totally strange behaviour because all I did was change the %age steps for other images as the animation pattern is absolutely same for all of them. But due some unknown reasons, other images are not following as expected and I don't see any logical reason. May be you could help me out!
jsFiddle
HTML:
<div id='slideshow'>
<figure id='imagestrip'>
<img src="images/img2.jpg" alt="Photograph of a Black kite">
<img src="images/img3.jpg" alt="Profile of a Red kite">
<img src="images/img4.jpg" alt="Pelicans on moorings at sea">
<img src="images/img9.jpg" alt="Photograph of Pariah kite">
</figure>
</div>
CSS:
#slideshow {
width: 80%;
margin: 0 auto;
height: 20em;
position: relative;
overflow: hidden;
perspective: 850px;
/* outline: 3px solid blue;*/
}
#slideshow figure {
position: absolute;
width: 400%;
height: 100%;
margin: 0;
transform-style: preserve-3d;
animation: slider2 30s infinite;
outline: 2px solid red;
}
figure img {
width: 25%;
height: 100%;
float: left;
outline: 3px solid yellow;
}
#keyframes slider2 {
0% {
transform: translateX(0%);
transform: translateZ(0px); /*Zoom-in*/
}
2% {
/* transform: translateX(-25%);*/
transform: translateZ(250px);
}
20% {
transform: translateX(0%);
transform: translateZ(250px);
}
22% {
transform: translateX(0%);
transform: translateZ(0px);
}
25% {
/*transform: translateX(-25%);*/
transform: translateZ(0);
transform: translateX(-25%);
}
27% {
/*transform: translateX(-25%);*/
transform: translateZ(250px);
transform: translateX(-25%);
}
45% {
transform: translateZ(250px);
transform: translateX(-25%);
}
47% {
transform: translateZ(0px);
transform: translateX(-25%);
}
50% {
/*transform: translateZ(100px);*/
transform: translateX(-50%);
/*transform: translateZ(0px);*/
}
57% {
transform: translateZ(250px);
transform: translateX(-50%);
}
75% {
transform: translateZ(250px);
transform: translateX(-50%);
}
77% {
transform: translateZ(0px);
transform: translateX(-50%);
}
80% {
/*transform: translateZ(250px);*/
transform: translateX(-75%);
}
My pattern is as follows:
An image Zooms-in for, say, 1s and stays for a while, say, 5s and then zooms-out again for 1s. then it slides left by transform: translateX(%). This pattern is successful for first image but as the second image slides in, nothing happens, though the animation rules are same for other images.
When you want to specify multiple transforms to an element, they should be set to the same property as space separated values and not add a second transform property with the next transform. If you do it that way, then the latest transform would override the one that was provided earlier within same keyframe.
For example, in the below keyframe only the transform: translateZ(0px) has a value.
0% {
transform: translateX(0%);
transform: translateZ(0px);
}
#slideshow {
width: 80%;
margin: 0 auto;
height: 20em;
position: relative;
overflow: hidden;
perspective: 850px;
/* outline: 3px solid blue;*/
}
#slideshow figure {
position: absolute;
width: 400%;
height: 100%;
margin: 0;
transform-style: preserve-3d;
animation: slider2 30s infinite;
outline: 2px solid red;
}
figure img {
width: 25%;
height: 100%;
float: left;
outline: 3px solid yellow;
}
#keyframes slider2 {
0% {
transform: translateX(0%) translateZ(0px);
}
2% {
transform: translateZ(250px);
}
20% {
transform: translateX(0%) translateZ(250px);
}
22% {
transform: translateX(0%) translateZ(0px);
}
25% {
transform: translateZ(0) translateX(-25%);
}
27% {
transform: translateZ(250px) translateX(-25%);
}
45% {
transform: translateZ(250px) translateX(-25%);
}
47% {
transform: translateZ(0px) translateX(-25%);
}
50% {
transform: translateX(-50%);
}
57% {
transform: translateZ(250px) translateX(-50%);
}
75% {
transform: translateZ(250px) translateX(-50%);
}
77% {
transform: translateZ(0px) translateX(-50%);
}
80% {
transform: translateX(-75%);
}
}
<div id='slideshow'>
<figure id='imagestrip'>
<img src="https://images.unsplash.com/41/NmnKzKIyQsyGIkFjiNsb_20140717_212636-3.jpg?q=80&fm=jpg&s=ce9ba69c9caf7d6483d874466478bc9b" alt="Photograph of a Black kite">
<img src="https://images.unsplash.com/41/NmnKzKIyQsyGIkFjiNsb_20140717_212636-3.jpg?q=80&fm=jpg&s=ce9ba69c9caf7d6483d874466478bc9b" alt="Profile of a Red kite">
<img src="https://images.unsplash.com/41/NmnKzKIyQsyGIkFjiNsb_20140717_212636-3.jpg?q=80&fm=jpg&s=ce9ba69c9caf7d6483d874466478bc9b" alt="Pelicans on moorings at sea">
<img src="https://images.unsplash.com/41/NmnKzKIyQsyGIkFjiNsb_20140717_212636-3.jpg?q=80&fm=jpg&s=ce9ba69c9caf7d6483d874466478bc9b" alt="Photograph of Pariah kite">
</figure>
</div>
Using keyframe animation, the div with an id of "Second" animates slightly before the "first" div starts to. Here is my code shouldn't they move at the same speed by default? any help would be great thanks.
body { background-color: black; color: white;}
#First { width: 200px;
height: 50px;
position: absolute;
top:5px;
color: black;
text-align: center;
background-color: yellow;
-webkit-transform-origin: top;
-webkit-animation: myfirst 1s;
-webkit-transform:rotateX(90deg);
-webkit-animation-iteration-count: infinite;
}
#-webkit-keyframes myfirst
{
0% {-webkit-transform:rotateX(0deg);}
100% {-webkit-transform:rotateX(90deg);}
}
#Second { width: 200px;
height: 50px;
position: absolute;
top:5px;
left:200px;
color: black;
text-align: center;
background-color: green;
-webkit-transform-origin: bottom;
-webkit-animation: mysecond 1s;
-webkit-transform:rotateX(0deg);
-webkit-animation-iteration-count: infinite;
}
#-webkit-keyframes mysecond
{
0% {-webkit-transform:rotateX(90deg);}
100% {-webkit-transform:rotateX(0deg);}
}
and the HTML,
<div id="First">FIRST</div>
<div id="Second">SECOND</div>
Code on jsfiddle: http://jsfiddle.net/x3p64/
Demo
#-webkit-keyframes were different for both
As per requirements
New Demo
#-webkit-keyframes myfirst {
0% {
-webkit-transform: scaleY(0);
}
20% {
-webkit-transform: scaleY(0.2);
}
40% {
-webkit-transform: scaleY(0.4);
}
60% {
-webkit-transform: scaleY(0.6);
}
80% {
-webkit-transform: scaleY(0.8);
}
100% {
-webkit-transform: scaleY(1);
}
}
#-webkit-keyframes mysecond {
0% {
-webkit-transform: scaleY(1);
}
20% {
-webkit-transform: scaleY(0.8);
}
40% {
-webkit-transform: scaleY(0.6);
}
60% {
-webkit-transform: scaleY(0.4);
}
80% {
-webkit-transform: scaleY(0.2);
}
100% {
-webkit-transform: scaleY(0);
}
}
It's not that it is starting before, it just looks like it because of the easing properties. Both animations are starting and stopping at the same time, they just look different. Try using a linear easing on both.
-webkit-animation: mysecond 1s linear;