<div class="background">
  <h1 class="title">
    <span>Ghosty</span>                         <span>Halloween</span>
  </h1>
  
  <div class="ghost ghost--1">
    <div class="ghost-close"></div>
    <div class="ghost-head">
      <div class="ghost-eye ghost-eye--left"></div>
      <div class="ghost-eye ghost-eye--right"></div>
      <div class="ghost-mouth"></div>
    </div>
    <div class="ghost-body">
      <div class="ghost-hand ghost-hand--1"></div>
      <div class="ghost-hand ghost-hand--2"></div>
      <div class="ghost-hand ghost-hand--3"></div>
      <div class="ghost-hand ghost-hand--4"></div>
      <div class="ghost-hand ghost-hand--5"></div>
    </div>
  </div>
  
  <div class="ghost ghost--2">
    <div class="ghost-close"></div>
    <div class="ghost-head">
      <div class="ghost-eye ghost-eye--left"></div>
      <div class="ghost-eye ghost-eye--right"></div>
      <div class="ghost-mouth"></div>
    </div>
    <div class="ghost-body">
      <div class="ghost-hand ghost-hand--1"></div>
      <div class="ghost-hand ghost-hand--2"></div>
      <div class="ghost-hand ghost-hand--3"></div>
      <div class="ghost-hand ghost-hand--4"></div>
      <div class="ghost-hand ghost-hand--5"></div>
    </div>
  </div>
  
  <div class="ghost ghost--3">
    <div class="ghost-close"></div>
    <div class="ghost-head">
      <div class="ghost-eye ghost-eye--left"></div>
      <div class="ghost-eye ghost-eye--right"></div>
      <div class="ghost-mouth"></div>
    </div>
    <div class="ghost-body">
      <div class="ghost-hand ghost-hand--1"></div>
      <div class="ghost-hand ghost-hand--2"></div>
      <div class="ghost-hand ghost-hand--3"></div>
      <div class="ghost-hand ghost-hand--4"></div>
      <div class="ghost-hand ghost-hand--5"></div>
    </div>
  </div>
  
  <div class="moon-orbit">
    <div class="moon">
      <div class="moon-hole moon-hole--1"></div>
      <div class="moon-hole moon-hole--2"></div>
      <div class="moon-hole moon-hole--3"></div>
      <div class="moon-hole moon-hole--4"></div>
      <div class="moon-hole moon-hole--5"></div>
      <div class="moon-hole moon-hole--6"></div>
      <div class="moon-hole moon-hole--7"></div>
      <div class="moon-hole moon-hole--8"></div>
    </div>
  </div>
  
  <div class="cloud"></div>
  <div class="cloud"></div>
  <div class="cloud"></div>
  <div class="cloud"></div>
  <div class="cloud"></div>
  <div class="cloud"></div>
  <div class="cloud"></div>
  
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  
</div>
@use "sass:math";

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

.background {
  background: radial-gradient(#3c3c3c, #0e0e0e);
  height: 100%;
  
}

.title {
  position: absolute;
  width: 100vw;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-family: 'Acme', sans-serif;
  font-size: 2.8em;
  color: #ff6600;
  text-shadow: 2px 2px #000000;
  text-align: center;
  z-index: 5;
  
  display: flex;
  
  span {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50%;
    transition: all 0.25s ease-out;
    
    &:first-child {
      left: -5px;
      text-align: right;
    }
    
    &:last-child {
      right: -5px;
      text-align: left;
    }
  }
  
  &.space {
    span:first-child {
      left: -40px;
    }
    span:last-child {
      right: -40px;
    }
  }
}

// Moon
.moon-orbit {
  position: absolute;
  top: calc(100vh + 800px);
  left: 50%;
  width: 2000px;
  height: 50%;
  z-index: 4;
  
  transform: translate(-50%,-50%) rotate(45deg);
  
  animation: moon-orbit 200s linear infinite;
}

.moon {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  background: rgba(212, 212, 212, 1);
  border-radius: 50%;
  overflow: hidden;
  
  animation: moon 100s linear infinite;
  
  .moon-hole {
    position: absolute;
    border-radius: 50%;
    box-shadow: 0 0 5px 1px rgba(0, 0, 0, 0.1) inset;
    background: rgba(196, 196, 196, 0.1);
    transform: translate(-50%, -50%);
    
    &.moon-hole--1 {
      top: 75%;
      left: 10%;
      width: 15px;
      height: 15px;
    }
    
    &.moon-hole--2 {
      top: 45%;
      left: 60%;
      width: 20px;
      height: 20px;
    }
    
    &.moon-hole--3 {
      top: 56%;
      left: 30%;
      width: 6px;
      height: 6px;
    }
    
    &.moon-hole--4 {
      top: 26%;
      left: 25%;
      width: 10px;
      height: 10px;
    }
    
    &.moon-hole--5 {
      top: 68%;
      left: 88%;
      width: 5px;
      height: 5px;
    }
    
    &.moon-hole--6 {
      top: 82%;
      left: 57%;
      width: 12px;
      height: 12px;
    }
    
    &.moon-hole--7 {
      top: -10%;
      left: 38%;
      width: 30px;
      height: 30px;
    }
    
    &.moon-hole--8 {
      top: 10%;
      left: 82%;
      width: 16px;
      height: 16px;
    }
  }
}

@keyframes moon-orbit {
  0%   { transform: translate(-50%,-50%) rotate(45deg) }
  100% { transform: translate(-50%,-50%) rotate(405deg) }
}

@keyframes moon {
  0%   { box-shadow: 0 0 4px 3px rgba(255, 255, 255, 0.3) }
  50%  { box-shadow: 0 0 6px 4px rgba(255, 255, 255, 0.6) }
  100% { box-shadow: 0 0 4px 3px rgba(255, 255, 255, 0.3) }
}

// Clouds
.cloud {
  position: absolute;
  background: white;
  opacity: 0.02;
  z-index: 4;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  
  left: -20%;
  
  &:before, &:after {
    content: '';
    position: absolute;
    background: white;
    border-radius: 50%;
  }
  
  &.cloud--1 {
    top: 70px;
    width: 100px; 
    height: 40px;
    border-radius: 40px;
    
    &:before {
      width: 40px;
      height: 40px;
      top: -20px;
      left: 15px;
    }

    &:after {
      width: 60px;
      height: 60px;
      top: -25px;
      right: 15px;
    }
  }
  
  &.cloud--2 {
    top: 150px;
    
    left: -20%;
    width: 80px;
    height: 30px;
    border-radius: 30px;

    &:before {
      width: 30px;
      height: 30px;
      top: -10px;
      right: 7px;
    }

    &:after {
      width: 40px;
      height: 40px;
      top: -20px;
      left: 10px;
    }
  }
  
  &.cloud--3 {
    top: 30px;
    left: -50%;
    width: 60px;
    height: 20px;
    border-radius: 20px;

    &:before {
      width: 25px;
      height: 25px;
      bottom: 10px;
      left: 8px;
    }

    &:after {
      width: 20px;
      height: 20px;
      bottom: 10px;
      right: 12px;
    }
  }
}

@keyframes cloud--1 {
  0%   { left: -20% }
  100% { left: 120% }
}

@keyframes cloud--2 {
  0%   { left: 120% }
  100% { left: -20% }
}

// Stars
.star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: white;
  border-radius: 50%;
  z-index: 3;
}

@keyframes pulse1 {
  0% { opacity: 0.4 }
  12% { opacity: 0.5 }
  34% { opacity: 0.2 }
  48% { opacity: 0.5 }
  55% { opacity: 0.1 }
  67% { opacity: 0.3 }
  73% { opacity: 0.5 }
  88% { opacity: 0.2 }
  100% { opacity: 0.4 }
}

@keyframes pulse2 {
  0% { opacity: 0.3 }
  13% { opacity: 0.5 }
  32% { opacity: 0.4 }
  41% { opacity: 0.5 }
  57% { opacity: 0.4 }
  62% { opacity: 0.5 }
  77% { opacity: 0.2 }
  90% { opacity: 0.5 }
  100% { opacity: 0.3 }
}

@keyframes pulse3 {
  0% { opacity: 0.5 }
  10% { opacity: 0.3 }
  36% { opacity: 0.2 }
  42% { opacity: 0.5 }
  54% { opacity: 0.4 }
  60% { opacity: 0.5 }
  71% { opacity: 0.3 }
  83% { opacity: 0.2 }
  100% { opacity: 0.5 }
}

@keyframes pulse4 {
  0% { opacity: 0.3 }
  15% { opacity: 0.5 }
  36% { opacity: 0.1 }
  44% { opacity: 0.5 }
  52% { opacity: 0.5 }
  66% { opacity: 0.4 }
  70% { opacity: 0.3 }
  88% { opacity: 0.5 }
  100% { opacity: 0.3 }
}

@keyframes pulse5 {
  0% { opacity: 0.2 }
  11% { opacity: 0.4 }
  37% { opacity: 0.3 }
  45% { opacity: 0.5 }
  54% { opacity: 0.3 }
  63% { opacity: 0.5 }
  76% { opacity: 0.2 }
  90% { opacity: 0.5 }
  100% { opacity: 0.2 }
}

// Ghost
.ghost {
  position: absolute;
  cursor: pointer;
  top: 100vh;
  transition: transform .25s ease;
  z-index: 6;
  
  .ghost-close {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 50%;
    
    opacity: 0;
    
    &:before, &:after {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      width: 50%;
      height: 2px;
      border-radius: 2px;
      background: rgba(255, 255, 255, 0.75);
    }
    
    &:before {
      transform: translate(-50%, -50%) rotate(45deg);
    }
    
    &:after {
      transform: translate(-50%, -50%) rotate(-45deg);
    }
    
  }
 
  .ghost-head,
  .ghost-body,
  .ghost-hand,
  .ghost-hand:after,
  .ghost-hand:before {
    background: white;
  }
  
  .ghost-head {
    position: relative;
    width: 100%;
    padding-top: 100%;
    border-radius: 50%;
    
    .ghost-eye,
    .ghost-mouth {
      position: absolute;
      background: black;
    }
    
    .ghost-eye {
      width: 10%;
      height: 10%;
      border-radius: 50%;
      
      &.ghost-eye--left,
      &.ghost-eye--right {
        top: 40%; 
      }
      
      &.ghost-eye--left {
        left: 25%;
      }
      
      &.ghost-eye--right {
        right: 25%;
      }
    }
    
    .ghost-mouth {
      width: 25%;
      height: 2px;
      border-radius: 2px;
      top: 58%;
      left: 50%;
      transform: translateX(-50%);
    }
  }
  
  .ghost-body {
    width: 100%;
    padding-top: 150%;
    margin-top: -50%;
    
    .ghost-hand {
      position: absolute;
      width: 20%;
      
      &:after, &:before {
        content: '';
        position: absolute;
        width: 100%;
        padding-top: 100%;
        border-radius: 50%;
      }
      
      &:after {
         top: 0;
         transform: translateY(-50%);
      }
      
      &:before {
        bottom: 0;
        transform: translateY(50%);
      }
      
      &.ghost-hand--2,
      &.ghost-hand--4,
      &.ghost-hand--2:after,
      &.ghost-hand--4:after,
      &.ghost-hand--2:before,
      &.ghost-hand--4:before {
        background: black;
      }

      
      &.ghost-hand--1 {
        top: 100%;
        left: 0;
        padding-top: 10%;
      }
      
      &.ghost-hand--2 {
        top: 90%;
        left: 20%;
        padding-top: 20%;
      }
      
      &.ghost-hand--3 {
        top: 100%;
        left: 40%;
        padding-top: 30%;
      }
      
      &.ghost-hand--4 {
        top: 90%;
        left: 60%;
        padding-top: 33%;
      }
      
      &.ghost-hand--5 {
        top: 100%;
        left: 80%;
        padding-top: 0%;
      }
    }
  }
  
  &.ghost--1 {
    left: calc(50% - 100px);
    width: 90px;
    transform: translate(-50%, -30px);
    
    &:hover {
      transform: translate(-50%, -50px);
    }
    
    .ghost-mouth {
      width: 25%;
      padding-top: 25%;
      border-bottom-left-radius: 25% * 2;
      border-bottom-right-radius: 25% * 2;
    }
  }
  
  &.ghost--2 {
    left: calc(50% + 90px);
    width: 70px;
    transform: translate(-50%, -20px);
    
    &:hover {
      transform: translate(-50%, -40px);
    }
  }
  
  &.ghost--3 {
    left: 50vw;
    width: 60px;
    transform: translate(-50%, -15px);
    
    &:hover {
      transform: translate(-50%, -32px);
    }
    
    .ghost-mouth {
      background: red;
      border-radius: 50%;
      
      &:after, &:before {
        content: '';
        position: absolute;
        width: 40%;
        padding-top: 15%;
        background: red;
        border-radius: 50%;
        top: -50%;
      }
      
      &:after {
        left: 5%;
      }
      
      &:before {
        right: 5%;
      }
    }
  }
  
  &.active {
    width: 60px;
    top: 50vh;
    left: 50vw;
    transform: translate(-50%, -50%);

    &:hover {
      transform: translate(-50%, -50%);
    }
    
    .ghost-close {
      opacity: 1;
      transition: opacity .25s .25s linear; 
    }
  }
}
View Compiled
const width = window.innerWidth;
const height = window.innerHeight;

let title = 
    document.querySelectorAll(".title")[0];

let clouds = document.querySelectorAll(".cloud");

let stars = document.querySelectorAll(".star");

let ghosts = document.querySelectorAll(".ghost");

[...stars].map(item => {
  item.style.top = Math.random() * 100 + "vh";
  item.style.left = Math.random() * 100 + "vw";
  item.style.animation = `pulse${Math.floor(Math.random() * 5 + 1)} 2.5s infinite`;
});

[...clouds].map(item => {
  item.classList.add(`cloud--${Math.floor(Math.random() * 3 + 1)}`);
  item.style.top = Math.random() * 100 + "vh";
  item.style.animationName = `cloud--${Math.floor((Math.random() * 2 + 1))}`;
  item.style.animationDuration = `${Math.floor(Math.random() * 50 + 25)}s`;
  item.style.animationDelay = `${Math.floor(Math.random() * 30 + 1)}s`
});

[...ghosts].map(item => {
 item.addEventListener("click",() => onGhostClicked(item));
});

const onGhostClicked = (item) => {
  if (!item.classList.contains("active")) {
    removeActiveGhosts();
    item.classList.add("active");
    title.classList.add("space");
  } else {
    removeActiveGhosts();  
  }
};

const removeActiveGhosts = () => {
  [...ghosts].map(item => {
 item.classList.remove("active");
  });
  title.classList.remove("space");
};


View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.