How to fix fullscreen #keyframes loader - css

On my website, I'm trying to make a simple white full-screen loader with one <div> element, but instead of going to the right at the end, the <div> element goes partially to the left, then snaps to the right. Any ideas on how to fix this? Here's a demo:
body {
background-color: #121212;
}
div#l {
position: absolute;
height: 100%;
top: 0;
background-color: white;
animation: loader 2s infinite;
}
#keyframes loader {
from {
left: 0;
width: 0;
}
49% {
width: 100%;
left: 0;
}
51% {
width: 100%;
right: 0;
}
to {
width: 0;
right: 0;
}
}
<div id='l'></div>

You should divide your keyframe in three equal parts.
from to 33%: the white div appear
from 33% to 66%: change the position of the div
from 66% to to: the white div disappear
Edit you keyframe like this:
#keyframes loader {
from {
left: 0;
width: 0;
}
33% {
width: 100%;
left: 0;
}
66% {
width: 100%;
right: 0;
}
to {
right: 0;
width: 0;
}
}
body {
background-color: #121212;
}
div#l {
position: absolute;
height: 100%;
top: 0;
background-color: white;
animation: loader 2s infinite;
}
#keyframes loader {
from {
left: 0;
width: 0;
}
33% {
width: 100%;
left: 0;
}
66% {
width: 100%;
right: 0;
}
to {
right: 0;
width: 0;
}
}
<div id='l'></div>
As you can see in this way the speed of the animation is not linear, and it is not the result we want.
I sugget you to divide the keyframe in two parts:
from to 50%: the white div appear
from 50% to to: the white div move itself to it's max left position
Therefore:
#keyframes loader {
from {
left: 0;
width: 0;
}
50% {
left: 0;
width: 100%;
}
to {
left: 100%;
width: 0;
}
}
body {
background-color: #121212;
}
div#l {
position: absolute;
height: 100%;
top: 0;
background-color: white;
animation: loader 2s infinite;
}
#keyframes loader {
from {
left: 0;
width: 0;
}
50% {
left: 0;
width: 100%;
}
to {
left: 100%;
width: 0;
}
}
<div id='l'></div>

Related

Why is my sprite sheet animation sliding?

Trying to implement a sprite sheet animation via css. I have followed this example
https://codepen.io/SitePoint/pen/zxXrzP
However, my animation is sliding vertically and I can not understand why. Any input appreciated.
.parent {
position: relative;
width: 70%;
margin: -10% auto 0 auto;
/* positioning tweak */
}
.parent:before {
content: "";
display: block;
padding-top: 61.37%;
}
.ryu {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-image: url("http://dev.froststudio.se/wp-content/uploads/2020/06/frostcell_v03.png");
background-size: 100%;
animation: sprite 4s steps(79) forwards;
}
#keyframes sprite {
from {
background-position: 0 0%;
}
to {
background-position: 0 100%;
}
}
http://dev.froststudio.se
Cheers,

Exploding particle: Animating with CSS

I'd like to simulate a particle explosion, from the center of a screen out to the edges (In CSS, and I promise to not use this for nefarious purposes)
Here's a visual so you know what I'm talking about:
BEFORE:
AFTER:
I've tried using the following HTML/CSS/JS, but it doesn't work (dots stay still in the middle of the screen):
The HTML is just this:
<div id="animated"></div>
The CSS:
// SCSS
#animated {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
.particle {
position: absolute;
left: 50%;
top: 50%;
width: 10px;
height: 10px;
transition: transform 1s ease-in-out;
&.on {
transform: translate(-30vw, -30vh);
}
&::after {
position: absolute;
content: "";
width: 10px;
height: 10px;
border-radius: 50%;
background: red;
}
}
}
And the Javascript:
document.addEventListener('DOMContentLoaded', onLoad);
function onLoad() {
// animate
for(var i = 0; i < 360; i+=5) {
const particle = createParticle(animated, i);
}
}
function createParticle(parentElem, rotation) {
const particle = document.createElement('div');
particle.style.transform = `rotate(${rotation}deg)`;
particle.classList.add('particle');
particle.classList.add('on'); // turn on
parentElem.appendChild(particle);
return particle;
}
Here's a link to a CodePen: https://codepen.io/floatingrock/pen/KKpxpvJ
Here is an idea with CSS variable where it's easy to adjust with few code.
Run on full screen for better result:
document.addEventListener('DOMContentLoaded', onLoad);
function onLoad() {
let parentElem = document.querySelector('.container');
for (var i = 0; i < 360; i += 10) {
const particle = document.createElement('div');
particle.style = `--r:${i}deg`;
parentElem.appendChild(particle);
}
}
.container {
width: 20px;
height: 20px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.container>div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
background: red;
transform: rotate(var(--r, 0deg)) translate(0);
animation: splash 1s infinite alternate 1s;
}
#keyframes splash {
to {
transform: rotate(var(--r, 0deg)) translate(44vmin);
}
}
<div class="container">
</div>
You can consider different delay for another kind of animation:
document.addEventListener('DOMContentLoaded', onLoad);
function onLoad() {
let parentElem = document.querySelector('.container');
for (var i = 0; i < 360; i += 10) {
const particle = document.createElement('div');
particle.style = `--r:${i}deg;--d:${(i/360)}s`;
parentElem.appendChild(particle);
}
}
.container {
width: 20px;
height: 20px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.container>div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
background: red;
transform: rotate(var(--r, 0deg)) translate(0);
animation: splash 1s infinite alternate var(--d,0s);
}
#keyframes splash {
to {
transform: rotate(var(--r, 0deg)) translate(44vmin);
}
}
<div class="container">
</div>
We can still optimize the code with less CSS:
document.addEventListener('DOMContentLoaded', onLoad);
function onLoad() {
let parentElem = document.querySelector('.container');
for (var i = 0; i < 360; i += 10) {
const particle = document.createElement('div');
particle.style = `--r:${i}deg`;
parentElem.appendChild(particle);
}
}
.container > div {
position: fixed;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
border-radius: 50%;
background: red;
transform:translate(-50%, -50%) rotate(var(--r, 0deg)) translate(0);
animation: splash 1s infinite alternate 1s;
}
#keyframes splash {
to {
transform:translate(-50%, -50%) rotate(var(--r, 0deg)) translate(calc(50vmin - 10px));
}
}
/* Irrelevant styles */
html {
height:100%;
border:1px solid blue; /* screen border*/
box-sizing:border-box;
background:linear-gradient(green,green) center/10px 10px no-repeat; /* the center of the screen */
}
body {
margin:0;
}
<div class="container">
</div>
The order of transformation is important. Related: Why does order of transforms matter? rotate/scale doesn't give the same result as scale/rotate

How do I achieve the effect that two div with the width of 50% open simultaneously?

I try to create the effect that two gates open simultaneously, I tried modifying the width property but I achieved the desired effect only on the left gate. The idea is that the right gate be closed from the center to the right border. Thanks in advance for your suggestions
body {
position: relative;
margin: 0;
background-color: goldenrod;
}
.gate {
position: absolute;
background-color: gray;
width: 50%;
height: 100vh;
float: left;
box-sizing: border-box;
animation-duration: 5s;
animation-fill-mode: forwards;
}
.left-gate {
animation-name: left;
border-right: 1px solid white;
top: 0;
left: 0;
}
.right-gate {
animation-name: right;
top: 0;
left: 50%;
}
#keyframes left {
from {
width: 50%;
}
to {
width: 0;
}
}
#keyframes right {
from {
width: 50%;
}
to {
width: 0;
}
}
<div class="gate left-gate"></div>
<div class="gate right-gate"></div>
Add right: 0 to the right gate:
body {
position: relative;
margin: 0;
background-color: goldenrod;
}
.gate {
position: absolute;
background-color: gray;
width: 50%;
height: 100vh;
float: left;
box-sizing: border-box;
animation-duration: 5s;
animation-fill-mode: forwards;
}
.left-gate {
animation-name: left;
border-right: 1px solid white;
top: 0;
left: 0;
}
.right-gate {
animation-name: right;
top: 0;
right: 0;
}
#keyframes left {
from {
width: 50%;
}
to {
width: 0;
}
}
#keyframes right {
from {
width: 50%;
}
to {
width: 0;
}
}
<div class="gate left-gate"></div>
<div class="gate right-gate"></div>

How to remove white gap between two skewed images?

I want to have two parts of one image to be join into one original image, where each one part should be a triangle form.
I've found a codepen where there are two elements with nested images, where i removed margins, but there is an ugly white border(gap) between elements.
How can i remove this one?
<div class='pageOption'>
<a href='#' class='option' data-inf='photo'>
<img src='http://imgsrc.hubblesite.org/hu/db/images/hs-2013-06-a-large_web.jpg'>
</a>
<a href='#' class='option' data-inf='cinema'>
<img src='http://imgsrc.hubblesite.org/hu/db/images/hs-2013-06-a-large_web.jpg'>
</a>
</div>
body { background: gainsboro; }
.pageOption {
overflow: hidden;
position: relative;
margin: 0 auto;
width: 40em; height: 27em;
}
.option, .option img { width: 100%; height: 100%; }
.option {
overflow: hidden;
position: absolute;
/* arctan(27 / 40) = 34.01935deg
* need to skew by 90deg - 34.01935deg = 55.98065deg
*/
transform: skewX(-55.98deg);
}
.option:first-child {
/* left: -.25em; */
transform-origin: 100% 0;
}
.option:last-child {
/* right: -.25em; */
transform-origin: 0 100%;
}
.option img { opacity: 1; transition: .5s; }
.option img:hover { opacity: 1; }
.option img, .option:after {
transform: skewX(55.98deg);
transform-origin: inherit;
}
.option:after {
position: absolute;
margin: .5em 1.65em;
color: white;
font: 500 1.25em Courier;
letter-spacing: .1em;
text-transform: uppercase;
content: attr(data-inf);
}
.option:first-child:after { top: 0; left: 0; }
.option:last-child:after { right: 0; bottom: 0; }
Change these styles
.option:first-child {
left: 0.1em;
transform-origin: 100% 0;
}
.option:last-child {
right: 0;
transform-origin: 0 100%;
}

3rd opac background doesn't work (multiple backgrounds with opacity in CSS3)

I couldn't understand why my 3rd background doesn't work?
what I tried is here: http://jsbin.com/yopodusu/1/edit , #page::after background doesn't work.
body {
line-height: 1;
overflow-y: scroll;
background: transparent url(http://i.imgur.com/SwFFw1i.gif) repeat top left;
}
body::after {
content: "";
background: url(http://i.imgur.com/QOSseW6.jpg);
top: 0;
left: 0;
bottom: 0;
right: 0;
position: fixed;
z-index: -2;
opacity: .150;
}
#page::after {
content: "";
background: url(http://www.zordor.com/w/1920x1200/6098.jpg) no-repeat right top;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
opacity: .150;
background-size: 35%;
}
What am I doing wrong?
regards
You've got this property overriding the element's visibility :
.clearfix:before,.clearfix:after {
content:"\0020";
display:block;
height:0;
visibility:hidden;
}
Add visibility : visible to your #page:after
And height : auto as well, or setup a specific height.
Which gives :
#page::after {
content: "";
background: url(http://www.zordor.com/w/1920x1200/6098.jpg) no-repeat right top;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
opacity: .150;
background-size: 35%;
visibility : visible;
height: auto;
}

Resources