Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <button id="togglePower">Toggle Power</button>
<button id="initTogglePower">START ►</button>
<div id="glow" data-group="switch"></div>
<div id="pong" data-group="switch">
  <span class="score__p1">3</span>
  <span class="score__p2">4</span>
  <b></b>
  <div class="paddle paddle__p1"></div>
  <div class="paddle paddle__p2"></div>
</div>

<svg data-group="switch" xmlns="http://www.w3.org/2000/svg" viewBox="14.9 .6 131 88.5" class="on">
  <path fill="#110803" d="M143.8 89.23h-127a1.92 1.92 0 0 1-1.9-1.92V2.52c0-1.06.85-1.91 1.9-1.91h127c1.05 0 1.91.85 1.91 1.91v84.79c0 1.06-.86 1.92-1.92 1.92z"/>
  <radialGradient id="a" cx="68.75" cy="44.63" r="69.3" gradientTransform="matrix(.9911 .1332 -.1084 .807 5.45 -.54)" gradientUnits="userSpaceOnUse">
    <stop offset="0" stop-color="#3b4251"/>
    <stop offset="1" stop-color="#251800"/>
  </radialGradient>
  <path fill="url(#a)" d="M143.8 89.23h-127a1.92 1.92 0 0 1-1.9-1.92V2.52c0-1.06.85-1.91 1.9-1.91h127c1.05 0 1.91.85 1.91 1.91v84.79c0 1.06-.86 1.92-1.92 1.92z"/>
  <path fill="#333" d="M110.07 74.78c-2.53 2.9-43.46 3.74-43.46 3.74s-39.95-.74-42.55-3.74c-2.61-3-1.63-57.47 0-60.55 2.28-4.32 82.39-5.9 86 0 2.9 4.7 2.53 57.66 0 60.55z"/>
  <radialGradient id="b" cx="67.27" cy="44.45" r="88.98" gradientTransform="matrix(1 0 0 .9089 0 4.05)" gradientUnits="userSpaceOnUse">
    <stop offset="0"/>
    <stop offset=".28" stop-color="#0f0f0f"/>
    <stop offset=".63" stop-color="#1a1a1a"/>
    <stop offset="1" stop-color="#1e1e1e"/>
  </radialGradient>
  <path fill="url(#b)" d="M109.38 74.3c-2.48 2.85-42.76 3.68-42.76 3.68s-39.31-.73-41.88-3.68-1.6-56.56 0-59.6c2.25-4.24 81.08-5.79 84.64 0 2.85 4.64 2.49 56.75 0 59.6z"/>
  <linearGradient id="c" x1="139.68" x2="76.08" y1="45.85" y2="45.85" gradientUnits="userSpaceOnUse">
    <stop offset="0"/>
    <stop offset="1" stop-color="#383651"/>
  </linearGradient>
  <path fill="url(#c)" d="M119.73 82.83l-.05-73.9 18.43-.05.05 73.95z"/>
  <path fill="#1a1a1a" d="M138.1 8.93v73.85h-18.37V8.93h18.38m.1-.1H119.63V82.88H138.21V8.83z"/>
  <linearGradient id="d" x1="120.69" x2="137.15" y1="30.91" y2="30.91" gradientUnits="userSpaceOnUse">
    <stop offset="0" stop-color="#13121d"/>
    <stop offset="1" stop-color="#0b0505"/>
  </linearGradient>
  <path fill="url(#d)" d="M120.74 45.9l-.05-29.94 16.41-.05.05 29.99z"/>
  <path fill="#1a1a1a" d="M137.1 15.96v29.9h-16.36v-29.9h16.36m.1-.1H120.64v30.1H137.2v-30.1z"/>
  <linearGradient id="e" x1="120.74" x2="137.1" y1="42.99" y2="42.99" gradientUnits="userSpaceOnUse">
    <stop offset="0" stop-color="#666666"/>
    <stop offset="1" stop-color="#333333"/>
  </linearGradient>
  <path fill="url(#e)" d="M120.74 40.14h16.35v5.7h-16.35z"/>
  <linearGradient id="f" x1="130.89" x2="134.1" y1="20.68" y2="20.68" gradientUnits="userSpaceOnUse">
    <stop offset="0" stop-color="#655a40"/>
    <stop offset="0" stop-color="#655a40"/>
    <stop offset="1" stop-color="#333333"/>
  </linearGradient>
  <circle cx="132.5" cy="20.68" r="1.6" fill="url(#f)"/>
  <path fill="#1a1a1a" d="M132.5 19.13a1.55 1.55 0 1 1 0 3.1 1.55 1.55 0 0 1 0-3.1m0-.1a1.65 1.65 0 1 0 0 3.3 1.65 1.65 0 0 0 0-3.3z"/>
  <linearGradient id="g" x1="124.46" x2="126.47" y1="22.09" y2="22.09" gradientUnits="userSpaceOnUse">
    <stop offset="0" stop-color="#655a40"/>
    <stop offset="0" stop-color="#655a40"/>
    <stop offset="1" stop-color="#333333"/>
  </linearGradient>
  <circle cx="125.46" cy="22.09" r="1.01" fill="url(#g)"/>
  <path fill="#1a1a1a" d="M125.46 21.13a.96.96 0 1 1 0 1.91.96.96 0 0 1 0-1.91m0-.1a1.06 1.06 0 1 0 0 2.12 1.06 1.06 0 0 0 0-2.12z"/>
  <linearGradient id="h" x1="124.46" x2="126.47" y1="26.31" y2="26.31" gradientUnits="userSpaceOnUse">
    <stop offset="0" stop-color="#655a40"/>
    <stop offset="0" stop-color="#655a40"/>
    <stop offset="1" stop-color="#333333"/>
  </linearGradient>
  <circle cx="125.46" cy="26.31" r="1.01" fill="url(#h)"/>
  <path fill="#1a1a1a" d="M125.46 25.35a.96.96 0 1 1 0 1.91.96.96 0 0 1 0-1.91m0-.1a1.06 1.06 0 1 0 0 2.12 1.06 1.06 0 0 0 0-2.12z"/>
  <g>
    <linearGradient id="i" x1="124.46" x2="126.47" y1="30.53" y2="30.53" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="1" stop-color="#333333"/>
    </linearGradient>
    <circle cx="125.46" cy="30.53" r="1.01" fill="url(#i)"/>
    <path fill="#1a1a1a" d="M125.46 29.57a.96.96 0 1 1 0 1.91.96.96 0 0 1 0-1.9m0-.1a1.06 1.06 0 1 0 0 2.1 1.06 1.06 0 0 0 0-2.1z"/>
  </g>
  <g>
    <linearGradient id="j" x1="124.46" x2="126.47" y1="34.75" y2="34.75" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="1" stop-color="#333333"/>
    </linearGradient>
    <circle cx="125.46" cy="34.75" r="1.01" fill="url(#j)"/>
    <path fill="#1a1a1a" d="M125.46 33.8a.96.96 0 1 1 0 1.9.96.96 0 0 1 0-1.9m0-.1a1.06 1.06 0 1 0 0 2.1 1.06 1.06 0 0 0 0-2.1z"/>
  </g>
  <g>
    <linearGradient id="k" x1="121.98" x2="123.31" y1="24.35" y2="24.35" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="1" stop-color="#333333"/>
    </linearGradient>
    <circle cx="122.65" cy="24.35" r=".67" fill="url(#k)"/>
    <path fill="#1a1a1a" d="M122.65 23.73a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.43.72.72 0 0 0 0-1.43z"/>
  </g>
  <g>
    <linearGradient id="l" x1="121.98" x2="123.31" y1="27.06" y2="27.06" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="1" stop-color="#333333"/>
    </linearGradient>
    <circle cx="122.65" cy="27.06" r=".67" fill="url(#l)"/>
    <path fill="#1a1a1a" d="M122.65 26.45a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.43.72.72 0 0 0 0-1.44z"/>
  </g>
  <g>
    <linearGradient id="m" x1="121.98" x2="123.31" y1="29.77" y2="29.77" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="1" stop-color="#333333"/>
    </linearGradient>
    <circle cx="122.65" cy="29.77" r=".67" fill="url(#m)"/>
    <path fill="#1a1a1a" d="M122.65 29.16a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.43.72.72 0 0 0 0-1.43z"/>
  </g>
  <g>
    <linearGradient id="n" x1="121.98" x2="123.31" y1="32.49" y2="32.49" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="1" stop-color="#333333"/>
    </linearGradient>
    <circle cx="122.65" cy="32.49" r=".67" fill="url(#n)"/>
    <path fill="#1a1a1a" d="M122.65 31.87a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.44.72.72 0 0 0 0-1.44z"/>
  </g>
  <g>
    <linearGradient id="o" x1="129.66" x2="135.33" y1="34.75" y2="34.75" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="0" stop-color="#655a40"/>
      <stop offset="1" stop-color="#333333"/>
    </linearGradient>
    <circle cx="132.5" cy="34.75" r="2.83" fill="url(#o)"/>
    <path fill="#1a1a1a" d="M132.5 31.96a2.78 2.78 0 1 1 0 5.57 2.78 2.78 0 0 1 0-5.57m0-.1a2.89 2.89 0 1 0 0 5.78 2.89 2.89 0 0 0 0-5.78z"/>
  </g>
  <path d="M121.73 41.49h1.94v2.99h-1.94z"/>
  <path d="M121.73 41.49h1.94v2.99h-1.94z"></path>
  <path fill="#1e0b0b" d="M124.44 41.49h1.94v2.99h-1.94z"></path>
  <path fill="#1e0b0b" d="M124.44 41.49h1.94v2.99h-1.94z"/>
  <path fill="#1a1a1a" d="M127.56 15.96h.42v24.18h-.42z"/>
</svg>

<svg mlns="http://www.w3.org/2000/svg" viewBox="14.9 .6 131 88.5" class="off">
  <path fill="#110803" d="M143.8 89.23h-127a1.92 1.92 0 0 1-1.9-1.92V2.52c0-1.06.85-1.91 1.9-1.91h127c1.05 0 1.91.85 1.91 1.91v84.79c0 1.06-.86 1.92-1.92 1.92z"/>
  <path fill="#1a1a1a" d="M110.55 75.13C108 78.06 66.61 78.9 66.61 78.9s-40.4-.75-43.04-3.78-1.65-58.13 0-61.25c2.3-4.36 83.32-5.95 86.98 0 2.92 4.76 2.55 58.32 0 61.25z"/>
  <path d="M109.38 74.3c-2.48 2.85-42.76 3.68-42.76 3.68s-39.31-.73-41.88-3.68-1.6-56.56 0-59.6c2.25-4.24 81.08-5.79 84.64 0 2.85 4.64 2.49 56.75 0 59.6zM119.73 82.83l-.05-73.9 18.43-.05.05 73.95z"/>
  <path fill="#1a1a1a" d="M138.1 8.93v73.85h-18.37V8.93h18.38m.1-.1H119.63V82.88H138.21V8.83z"/>
  <path d="M120.74 45.9l-.05-29.94 16.41-.05.05 29.99z"/>
  <path fill="#1a1a1a" d="M137.1 15.96v29.9h-16.36v-29.9h16.36m.1-.1H120.64v30.1H137.2v-30.1z"/>
  <path fill="#1a1a1a" d="M120.74 40.14h16.35v5.7h-16.35z"/>
  <circle cx="132.5" cy="20.68" r="1.6" fill="#211e1c"/>
  <path fill="#1a1a1a" d="M132.5 19.13a1.55 1.55 0 1 1 0 3.1 1.55 1.55 0 0 1 0-3.1m0-.1a1.65 1.65 0 1 0 0 3.3 1.65 1.65 0 0 0 0-3.3z"/>
  <circle cx="125.46" cy="22.09" r="1.01" fill="#211e1c"/>
  <path fill="#1a1a1a" d="M125.46 21.13a.96.96 0 1 1 0 1.91.96.96 0 0 1 0-1.91m0-.1a1.06 1.06 0 1 0 0 2.12 1.06 1.06 0 0 0 0-2.12z"/>
  <circle cx="125.46" cy="26.31" r="1.01" fill="#211e1c"/>
  <path fill="#1a1a1a" d="M125.46 25.35a.96.96 0 1 1 0 1.91.96.96 0 0 1 0-1.91m0-.1a1.06 1.06 0 1 0 0 2.12 1.06 1.06 0 0 0 0-2.12z"/>
  <circle cx="125.46" cy="30.53" r="1.01" fill="#211e1c"/>
  <path fill="#1a1a1a" d="M125.46 29.57a.96.96 0 1 1 0 1.91.96.96 0 0 1 0-1.9m0-.1a1.06 1.06 0 1 0 0 2.1 1.06 1.06 0 0 0 0-2.1z"/>
  <circle cx="125.46" cy="34.75" r="1.01" fill="#211e1c"/>
  <path fill="#1a1a1a" d="M125.46 33.8a.96.96 0 1 1 0 1.9.96.96 0 0 1 0-1.9m0-.1a1.06 1.06 0 1 0 0 2.1 1.06 1.06 0 0 0 0-2.1z"/>
  <circle cx="122.65" cy="24.35" r=".67" fill="#211e1c"/>
  <path fill="#1a1a1a" d="M122.65 23.73a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.43.72.72 0 0 0 0-1.43z"/>
  <g>
    <circle cx="122.65" cy="27.06" r=".67" fill="#211e1c"/>
    <path fill="#1a1a1a" d="M122.65 26.45a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.43.72.72 0 0 0 0-1.44z"/>
  </g>
  <g>
    <circle cx="122.65" cy="29.77" r=".67" fill="#211e1c"/>
    <path fill="#1a1a1a" d="M122.65 29.16a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.43.72.72 0 0 0 0-1.43z"/>
  </g>
  <g>
    <circle cx="122.65" cy="32.49" r=".67" fill="#211e1c"/>
    <path fill="#1a1a1a" d="M122.65 31.87a.62.62 0 1 1 0 1.23.62.62 0 0 1 0-1.23m0-.1a.72.72 0 1 0 0 1.44.72.72 0 0 0 0-1.44z"/>
  </g>
  <g>
    <circle cx="132.5" cy="34.75" r="2.83" fill="#211e1c"/>
    <path fill="#1a1a1a" d="M132.5 31.96a2.78 2.78 0 1 1 0 5.57 2.78 2.78 0 0 1 0-5.57m0-.1a2.89 2.89 0 1 0 0 5.78 2.89 2.89 0 0 0 0-5.78z"/>
  </g>
  <path d="M121.73 41.49h1.94v2.99h-1.94z"/>
  <path fill="#1e0b0b" d="M124.44 41.49h1.94v2.99h-1.94z"/>
  <path fill="#1a1a1a" d="M127.56 15.96h.42v24.18h-.42z"/>
</svg>
              
            
!

CSS

              
                $transitionMain: all 0.2s ease-in-out;

$ntsc: ntsc 0.5s infinite;
$flickerStrength: 0.91;

$powerOn: tvOn 0.4s forwards;
$powerOff: tvOff 0.4s forwards;
$svgOpacity: 0.4;

$textGlow: 0 0 2vh rgba(255, 255, 255, 0.52);
$boxGlow: 0 0 2vh rgba(255, 255, 255, 0.1) inset,
  0 0 2vh rgba(255, 255, 255, 0.52);

body {
  background: #000;
  color: #fff;
  font-family: "press start 2p", sans-serif;
}

button {
  position: fixed;
}

#togglePower {
  left: 50%;
  bottom: 15%;
  width: 200px;
  opacity: 0.52;
  transition: $transitionMain;
  height: 5vh;
  background-color: #252525;
  color: #ccc;
  border: none;
  min-height: 44px;
  transform: translateX(-50%);
  z-index: 12;
  box-shadow: 0 0 10px #333 inset;
  display: none;
  border-radius: 1vh;
  outline-offset: 0;
  outline: none;
  &.activePower {
    display: block;
  }
  &:hover {
    opacity: 1;
    box-shadow: 0 0 25px #333 inset;
  }
  &:hover:active {
    background-color: #fff;
    color: #000;
    box-shadow: 0 0 25px #666 inset;
  }
}

#initTogglePower {
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0.8;
  border: 0;
  cursor: pointer;
  top: 0;
  left: 0;
  line-height: 50%;
  display: block;
  color: #666;
  z-index: 100;
  transition: $transitionMain;
  &:hover {
    opacity: 0.52;
    color: #fff;
  }
}

#glow {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(
    farthest-corner at 50% 70%,
    #111 0%,
    #000 50%,
    #000 100%
  );
  opacity: 0;
  transition: $transitionMain;
  pointer-events: none;
  &.active {
    animation: ntsc 0.5s infinite;
  }
}

#pong {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-64.5%, -50.5%) scale(0);
  width: 34vh;
  height: 25vh;
  z-index: 11;
  transition: $transitionMain;
  animation-direction: alternate;
  &.active {
    animation: $powerOn;
  }
  &.inactive {
    animation: $powerOff;
  }
  &:before {
    content: "";
    border-left: 0.3vh dashed #fff;
    display: block;
    position: absolute;
    height: 100%;
    left: 50%;
    transform: translateX(-0.25vh);
  }
  &:after {
    content: "";
    box-shadow: $boxGlow;
    z-index: 100;
    width: 0.3vh;
    display: block;
    position: absolute;
    height: 100%;
    left: 50%;
    transform: translateX(-0.25vh);
    animation: ntsc 0.5s infinite;
  }
}

span {
  position: absolute;
  top: 5%;
  width: 50%;
  padding: 0 5%;
  box-sizing: border-box;
  font-size: 2.5vh;
  text-shadow: $textGlow;
  animation: ntsc 0.5s;
}
.score__p1 {
  left: 0;
  text-align: right;
}
.score__p2 {
  right: 0;
}

b {
  position: absolute;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
  width: 0.75vh;
  height: 0.75vh;
  box-sizing: border-box;
  font-size: 2.5vh;
  z-index: 1000;
  background-color: #fff;
  box-shadow: $boxGlow;
  animation: ntsc 0.5s;
}

.paddle {
  width: 2%;
  height: 12%;
  position: absolute;
  background-color: #fff;
  box-shadow: $boxGlow;
  animation: ntsc 0.5s;
  transform: translateY(-50%);
  z-index: 12;
  top: 47.5%;
}

.paddle__p1 {
  left: 2vh;
  top: 25%;
}
.paddle__p2 {
  right: 2vh;
}

svg {
  width: 50vh;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: $transitionMain;
}

.off {
  fill-opacity: 1;
}
.on {
  fill-opacity: 0;
  z-index: 10;
}
.active {
  fill-opacity: $svgOpacity;
  animation: $ntsc;
}

@keyframes ntsc {
  $s: 30; // 60/2 = 30; 30fps over .5s = 60fps over 1s.  Virtually the same effect without the extra bloat.
  @for $i from 0 through $s {
    #{percentage($i*(1/$s))} {
      opacity: random(50) /
        100 +
        $flickerStrength; // Simulate the 60hz flicker.
    }
  }
}

@keyframes tvOn {
  0% {
    transform: translate(-64.5%, -50.5%) scale(0);
  }
  50% {
    transform: translate(-64.5%, -50.5%) scale(1, 0.1);
  }
  100% {
    transform: translate(-64.5%, -50.5%) scale(1, 1);
  }
}

@keyframes tvOff {
  0% {
    transform: translate(-64.5%, -50.5%) scale(1, 1);
  }
  100% {
    transform: translate(-64.5%, -50.5%) scale(0);
  }
  50% {
    transform: translate(-64.5%, -50.5%) scale(1, 0.1);
  }
}

@media screen and (max-width: 640px) {
  #glow {
    bottom: 0vh;
    top: initial;
    left: -30vw;
    width: 160vw;
    height: 80vh;
  }
}

              
            
!

JS

              
                // Added init power button to get around media restrictions.

const powerButton = document.getElementById("togglePower");
const initPowerButton = document.getElementById("initTogglePower");
const toggleGroup = document.querySelectorAll('[data-group="switch"]');

// SFX
const crickets = new Audio("//itsrynenotryan.com/codepen/pong/crickets.mp3");
const hum = new Audio("//itsrynenotryan.com/codepen/pong/hum.mp3");
const audioOn = new Audio("//itsrynenotryan.com/codepen/pong/on.mp3");
const audioOff = new Audio("//itsrynenotryan.com/codepen/pong/off.mp3");
const paddleHit = new Audio("//itsrynenotryan.com/codepen/pong/paddleHit.mp3");
const wallHit = new Audio("//itsrynenotryan.com/codepen/pong/wallHit.mp3");

let mv = 1; // Master Volume
crickets.volume = mv / 3;
hum.volume = mv / 4;
audioOn.volume = mv;
audioOff.volume = mv;
paddleHit.volume = mv / 8;
wallHit.volume = mv / 8;
crickets.loop = true;
hum.loop = true;

powerButton.addEventListener("click", powerSwitch);
initPowerButton.addEventListener("click", init);

function init() {
  setTimeout(function() {
    audioOn.play();
    crickets.play();
    hum.play();
    ball.play();
    p1.play();
    p2.play();
    [].map.call(toggleGroup, function(el) {
      el.classList.toggle("active");
    });
    initPowerButton.remove();
    powerButton.classList.add("activePower");
  }, 250);
}

// Power Switch Button
function powerSwitch() {
  if (document.getElementsByClassName("active").length != 3) {
    audioOn.currentTime = 0; // Ensures we can handle click-heavy users.
    audioOn.play();
    ball.play();
    p1.play();
    p2.play();
    hum.play();
  } else {
    audioOff.currentTime = 0; // Ensures we can handle click-heavy users.
    audioOff.play();
    ball.pause();
    p1.pause();
    p2.pause();
    hum.pause();
    hum.currentTime = 0;
    crickets.play();
  }
  [].map.call(toggleGroup, function(el) {
    el.classList.toggle("active");
    el.classList.toggle("inactive");
  });
}

// Ball Animation
var ball = anime({
  targets: "b",
  translateX: [
    {
      value: "13.6vh",
      duration: 750
    },
    {
      value: "3vh",
      duration: 500
    },
    {
      value: "-14.3vh",
      duration: 1000
    },
    {
      value: "0vh",
      duration: 750
    }
  ],
  translateY: [
    {
      value: "6vh",
      duration: 750
    },
    {
      value: "12vh",
      duration: 500
    },
    {
      value: "-4vh",
      duration: 1000
    },
    {
      value: "0vh",
      duration: 750
    }
  ],
  loop: true,
  autoplay: false,
  easing: "linear",
  duration: 3000,

  // Ball SFX
  update: function(anim) {
    let time = Math.round(anim.currentTime / 10) * 10; // Current time callback rounded for browser compatibility.
    if (time == 750) {
      paddleHit.play();
    }
    if (time == 1250) {
      wallHit.play();
    }
    if (time == 2250) {
      paddleHit.play();
    }
  }
});

// Player 1 Paddle Animation
var p1 = anime({
  targets: ".paddle__p1",
  translateY: [
    {
      value: "1.3vh",
      duration: 375,
      delay: 750
    },
    {
      value: "5vh",
      duration: 375
    },
    {
      value: "1.5vh",
      duration: 250,
      delay: 250
    },
    {
      value: "0",
      duration: 750,
      delay: 250
    }
  ],
  loop: true,
  autoplay: false,
  easing: "linear"
});

// Player 2 Paddle Animation
var p2 = anime({
  targets: ".paddle__p2",
  translateY: [
    {
      value: "2vh",
      duration: 250
    },
    {
      value: "5vh",
      duration: 250
    },
    {
      value: "4vh",
      duration: 500,
      delay: 1250
    },
    {
      value: "0",
      duration: 500,
      delay: 250
    }
  ],
  loop: true,
  autoplay: false,
  easing: "linear"
});

              
            
!
999px

Console