비전공자 개발일기

Javascript Particles 본문

Javascript

Javascript Particles

HiroDaegu 2022. 7. 5. 00:02
728x90
SMALL

 

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JAVASCRIPT PARTICLES</title>
  <link rel="stylesheet" href="style.css">
  <script defer src="main.js"></script>
</head>
<body>
  
</body>
</html>
* {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background-color: #111;
  overflow: hidden;
}

span {
  position: absolute;
  background-color: #F00;
  width: 10px;
  height: 10px;
  pointer-events: none;
  border-radius: 50%;
}

span::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #FFF;
  animation: moveParticles 2s linear infinite;
}

@keyframes moveParticles {
  0% {
    transform: translate(0);
  }
  100% {
    transform: translate(300px);
  }
}
document.addEventListener('mousemove', function(e) {
  let body = document.querySelector('body');
  let particles = document.createElement('span');
  let x = e.offsetX;
  let y = e.offsetY;
  particles.style.left = `${x}px`;
  particles.style.top = `${y}px`;

  let size = Math.random() * 8;
  particles.style.width = `${2 + size}px`; 
  particles.style.height = `${2 + size}px`; 

  let transformValue = Math.random() * 360;
  particles.style.transform = `rotate(${transformValue}deg)`;

  body.appendChild(particles);

  setTimeout(function() {
    particles.remove()
  }, 2000)
})
728x90
LIST

'Javascript' 카테고리의 다른 글

QR code Generator  (0) 2022.07.07
Heart Animation Effects  (0) 2022.07.06
Analog Clock  (0) 2022.07.03
Automatic Image Slider  (0) 2022.06.30
Toast Notification  (0) 2022.06.29