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