<main>
</main>
<div id="nyan-container" title="Click anywhere to remove nyan">
</div>
<footer>
  Pen by <a href="https://www.jemimaabu.com" target="_blank" rel="noopener">Jemima Abu ☃️</a>
</footer>
@import url("https://fonts.googleapis.com/css2?family=Pacifico&display=swap");

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

main {
  background-color: #003366;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Pacifico", cursive;
  height: 100vh;
  padding: 20px;
  text-align: center;
}

h1 {
  color: white;
}

#nyan-container {  
  height: 100vh;
  overflow: hidden;
  position: absolute;
  top: 0;
  transition: opacity 500ms;
  width: 100%;
}

.nyan {
  background-image: url('https://www.pngall.com/wp-content/uploads/2016/06/Nyan-Cat-PNG-Image.png');
  background-size: contain;
  animation: move ease-in infinite;
  position: absolute;
  width: 50px;
  height: 50px;
  top: 0;
  left: 0;
}

footer {
  background-color: #ffdfb9;
  bottom: 0;
  font-family: sans-serif;
  padding: 1rem;
  text-align: center;
  width: 100%;
}

footer a {
  color: inherit;
  text-decoration: none;
}

footer .heart {
  color: #dc143c;
}

@keyframes move {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    left: 100vw;
    opacity: 1;
  }
}
const nyanContainer = document.getElementById("nyan-container");

const random = (num) => {
  return Math.floor(Math.random() * num);
}

const getRandomStyles = () => {
  const top = random(100);
  const left = random(100);
  const dur = random(5) + 5;
  const size = random(200) + 50;
  return `
    top: ${top}%;
    left: -${left}%;
    animation-duration: ${dur}s;
    width: ${size}px;
    height: ${size}px;
  `;
}

const createNyan = (num) => {
  for (var i = num; i > 0; i--) {
    var nyan = document.createElement("div");
    nyan.className = "nyan";
    nyan.style.cssText = getRandomStyles();
    nyanContainer.append(nyan);
  }
}

const removeNyan = () => {
  nyanContainer.style.opacity = "0";
  setTimeout(() => {
    nyanContainer.remove()
  }, 500)
}

window.addEventListener("load", () => {
  createNyan(15)
  setTimeout(removeNyan, (1000 * 60))
});

window.addEventListener("click", () => {
  removeNyan()
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.