비전공자 개발일기

Heart Animation Effects 본문

Javascript

Heart Animation Effects

HiroDaegu 2022. 7. 6. 00:30
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>HEART ANIMATION EFFECTS</title>
  <link rel="stylesheet" href="style.css">
  <script defer src="main.js"></script>
</head>
<body>
  
</body>
</html>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

span {
  position: absolute;
  pointer-events: none;
  filter: drop-shadow(0 0 15px rgba(0, 0, 0, .6));
  animation: fadeInOut 1s linear infinite
}

@keyframes fadeInOut {
  0%, 100% {
    opacity: 0;
  }
  20%, 80% {
    opacity: 1;
  }
}

span::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background: url('./heart.png');
  background-size: cover;
  animation: moveShape 1s linear infinite
}

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

  let size = Math.random() * 80;
  heart.style.width = `${20 + size}px`;
  heart.style.height = `${20 + size}px`;

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

  body.appendChild(heart);

  setTimeout(function() {
    heart.remove()
  }, 1000);
})
728x90
LIST

'Javascript' 카테고리의 다른 글

Chatbot  (0) 2022.07.08
QR code Generator  (0) 2022.07.07
Javascript Particles  (0) 2022.07.05
Analog Clock  (0) 2022.07.03
Automatic Image Slider  (0) 2022.06.30