Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!-- Click on cloud! -->

<!-- Design rights purchased with altering permissions from Marija Stanic original at https://dribbble.com/shots/6171532-Baby-cloud -->
<svg viewBox="0 0 15.09 9.82" class="clouds cloud1" id="cloud1">
  <path  d="M3.9,9.78a2.81,2.81,0,0,1-.5,0,3.35,3.35,0,0,1-.83-6.61,5,5,0,0,1,9.56.89h.07a2.86,2.86,0,1,1,0,5.72H3.9Z"/>
</svg>

<svg viewBox="0 0 29.45 17.45" class="clouds cloud2" id="cloud2">
    <path d="M26.06,17.45H4.66A4.68,4.68,0,0,1,3.1,8.37,7.94,7.94,0,0,1,13.2,1.82,4.61,4.61,0,0,1,16.87,0a4.69,4.69,0,0,1,4.65,4.74h.19a4.73,4.73,0,0,1,4.72,4.74,4.83,4.83,0,0,1-.2,1.37,3.3,3.3,0,0,1-.11,6.6Z"/>
</svg>

<svg viewBox="0 0 15.45 9.45" class="clouds cloud3" id="cloud3">
    <path d="M13.57,9.45H2A2,2,0,0,1,0,7.47,2,2,0,0,1,1,5.75a4.9,4.9,0,0,1-.11-1A4.69,4.69,0,0,1,5.53,0,4.63,4.63,0,0,1,9.62,2.48a2.66,2.66,0,0,1,1.63-.56A2.75,2.75,0,0,1,14,4.73a3,3,0,0,1-.11.79,2,2,0,0,1-.27,3.93Z" />
</svg>

<svg viewBox="0 0 11.82 7.82" class="clouds cloud4" id="cloud4">
    <path d="M8.8,7.79a2.34,2.34,0,0,0,.38,0,2.67,2.67,0,0,0,.64-5.26,3.9,3.9,0,0,0-7.5.67H2.26a2.3,2.3,0,0,0,0,4.59H8.8Z" />
</svg>

<svg viewBox="0 0 25.45 13.09" class="clouds cloud5" id="cloud5">
  <path d="M2.52,13.09H22.18a3.3,3.3,0,0,0,.53-6.56,2.47,2.47,0,0,0,.1-.67A2.22,2.22,0,0,0,20.6,3.62a2.33,2.33,0,0,0-.7.11A6.56,6.56,0,0,0,8.75,2.61a4.77,4.77,0,0,0-1.82-.37A4.69,4.69,0,0,0,2.42,8.11a2.49,2.49,0,0,0,.1,5Z" />
</svg>

<div style="position: absolute; width: 100%; height: 100%" id="extra-clouds"></div>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48.09 29.36" id="happy-cloud" class="pos-center">
  <g id="main">
    <path id="cloud" d="M43.36,16.67a9.4,9.4,0,0,0,.23-2.05A8.8,8.8,0,0,0,30,7.16,14.61,14.61,0,0,0,2.87,14.68a14.14,14.14,0,0,0,.25,2.68,6.47,6.47,0,0,0,3.31,12h35.3a6.46,6.46,0,0,0,1.63-12.69Z"/>
    <path id="mouth" d="M18.85,22.49a2.32,2.32,0,0,1-.46,0,2.21,2.21,0,0,1-1.51-1.17.31.31,0,0,1,.56-.28,1.58,1.58,0,0,0,2.48.45.31.31,0,0,1,.44,0,.32.32,0,0,1,0,.45A2.2,2.2,0,0,1,18.85,22.49Z"/>
      <ellipse class="cheeks" cx="9.7" cy="19" rx="2.7" ry="2.1" transform="rotate(12) translate(4, -2)"/>
      <ellipse class="cheeks" cx="28" cy="17" rx="2.7" ry="2.1" transform="rotate(12) translate(4, -2)"/>
    <g id="eye_left" class="eye">
      <ellipse class="open" cx="11.92" cy="16.26" rx="1.75" ry="1.76" transform="translate(-2.88 2.57) rotate(-11)"/>
      <circle class="fleck" cx="12.39" cy="15.83" r="0.65"/>
    </g>
    <g id="eye_right" class="eye">
      <ellipse class="open" cx="26.54" cy="18.03" rx="1.75" ry="1.76" transform="translate(-2.95 5.4) rotate(-11)"/>
      <circle class="fleck" cx="27.01" cy="17.6" r="0.65"/>
  </g>
  </g>
</svg>

            
          
!
            
              :root {
  --bg: #13142b;
  --clouds: #2b344d;
  --open: #14132b;
  --fleck: #87aad5;
  --mouth: #14132b;
  --cloud: #87aad5;
  --dur: 1s;
}
.day {
  --bg: #A9C8E1;
  --clouds: #C8E1F1;
  --open:#2b344d;
  --fleck: #E0F0F7;
  --mouth: #2b344d;
  --cloud: #E0F0F7;
}

* {
  margin: 0;
  padding: 0;
}
body,
html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color:  rgba(255, 255, 255, 0);
}
body {
  background: var(--bg);
  transition: background var(--dur);
}
svg {
  visibility: hidden;
  position: absolute;
}
.pos-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate3d(-50%, -50%, 0);
}
#happy-cloud {
  margin-left: 2vmin;
  overflow: visible;
}

#cloud {
  fill: var(--cloud);
  transition: fill var(--dur);
}
#happy-cloud *:hover {cursor: pointer}
#mouth {
  fill: var(--mouth);
  transition: fill var(--dur);
}
.clouds {
  fill: var(--clouds);
  transition: fill var(--dur);
}
.open {
  fill: var(--open);
  transition: fill var(--dur);
}
.fleck {
  fill: var(--fleck);
  transition: fill var(--dur);
}
.cheeks {
  opacity: 0;
  fill: var(--bg);
  transition: var(--dur);
}

.heart {
  position: absolute;
}
.heart:before,
.heart:after {
  position: absolute;
  content: "";
  left: 5vmin;
  top: 0;
  width: 5vmin;
  height: 8vmin;
  background: currentColor;
  border-radius: 5vmin 5vmin 0 0;
  transform: rotate(-45deg);
  transform-origin: 0 100%;
}
.heart:after {
  left: 0;
  transform: rotate(45deg);
  transform-origin: 100% 100%;
}

            
          
!
            
              let heartTimer = null
const bounce = new TimelineMax({
  repeat: -1
});
const main = document.getElementById("main");
const mouth = document.getElementById("mouth");
bounce
  .set(mouth, { scale: 1.3, y: 0.25, transformOrigin: "center" })
  .to(
    main,
    2.5,
    {
      ease: Power1.easeInOut,
      y: -5,
      transformOrigin: "center",
      scale: 1.04,
      rotation: 0.5
    },
    0.05
  )
  .to(
    main,
    2.5,
    {
      ease: Power1.easeInOut,
      y: 0,
      transformOrigin: "center",
      scale: 1,
      rotation: 0
    },
    3.15
  );

const fleck = document.getElementsByClassName("fleck");
const eyes = document.getElementsByClassName("eye");
const blink = new TimelineMax({ repeat: -1 });
blink
  .to(eyes, 0.1, { scaleY: 0.3, transformOrigin: "center" }, 6)
  .to(fleck, 0.05, { opacity: 0 }, 6)
  .to(eyes, 0.1, { scaleY: 1, transformOrigin: "center" })
  .to(fleck, 0.1, { opacity: 1 }, 6.15);

const placeExtraClouds = ({
  id,
  left,
  waveLength,
  innerWidth,
  freq,
  width
}) => {
  let items = freq - 1;
  let curLeft = left;
  while (items > 0) {
    const nextLeft = curLeft - waveLength;
    if (nextLeft + width > 0) {
      curLeft = nextLeft;
      items--;
    } else {
      curLeft = nextLeft + innerWidth;
      items--;
    }
    const addCloud = document.getElementById(id).cloneNode(true);
    addCloud.id = "";
    addCloud.style.left = curLeft;
    document.getElementById("extra-clouds").append(addCloud);
  }
};

const initClouds = () => {
  const { innerWidth, innerHeight } = window;
  const happyCloud = document.getElementById("happy-cloud");
  const ratio = 1.6379;
  let height;
  let width;
  if (innerWidth > innerHeight) {
    height = innerHeight * 0.45;
    width = height * ratio;
  } else {
    width = innerWidth * 0.73;
    height = width / ratio;
  }
  happyCloud.style.width = width;
  happyCloud.style.height = height;
  happyCloud.style.visibility = "visible";

  const { left, top, bottom, right } = happyCloud.getBoundingClientRect();
  const freq = Math.round(innerWidth / (width * 1.5));
  const waveLength = innerWidth / freq;
  const extraClouds = document.getElementById("extra-clouds");
  while (extraClouds.hasChildNodes()) {
    extraClouds.removeChild(extraClouds.lastChild);
  }

  // Place all clouds in relation to happy cloud
  const cloud1 = document.getElementById("cloud1");
  cloud1.style.width = width * 0.32;
  cloud1.style.left = left + width * 0.45;
  cloud1.style.top = top - height * 1.02;
  cloud1.style.visibility = "visible";
  placeExtraClouds({
    id: "cloud1",
    left: left + width * 0.45,
    waveLength,
    innerWidth,
    freq
  });

  const cloud2 = document.getElementById("cloud2");
  cloud2.style.width = width * 0.63;
  cloud2.style.left = left - width * 0.35;
  cloud2.style.top = top - height * 0.7;
  cloud2.style.visibility = "visible";
  placeExtraClouds({
    id: "cloud2",
    left: left - width * 0.35,
    waveLength,
    innerWidth,
    freq,
    width: width * 0.63
  });

  const cloud3 = document.getElementById("cloud3");
  cloud3.style.width = width * 0.32;
  cloud3.style.left = right + width * 0.02;
  cloud3.style.top = top - height * 0.03;
  cloud3.style.visibility = "visible";
  placeExtraClouds({
    id: "cloud3",
    left: right + width * 0.02,
    waveLength,
    innerWidth,
    freq,
    width: width * 0.32
  });

  const cloud4 = document.getElementById("cloud4");
  cloud4.style.width = width * 0.25;
  cloud4.style.left = right - width * 0.12;
  cloud4.style.top = bottom + height * 0.15;
  cloud4.style.visibility = "visible";
  placeExtraClouds({
    id: "cloud4",
    left: right - width * 0.12,
    waveLength,
    innerWidth,
    freq,
    width: width * 0.25
  });

  const cloud5 = document.getElementById("cloud5");
  cloud5.style.width = width * 0.5;
  cloud5.style.left = left;
  cloud5.style.top = bottom + height * 0.3;
  cloud5.style.visibility = "visible";
  placeExtraClouds({
    id: "cloud5",
    left: left,
    waveLength,
    innerWidth,
    freq,
    width: width * 0.5
  });
};

// Clouds parallax
let loops = 1;
const anim = () => {
  const clouds = document.getElementsByClassName("clouds");
  for (let i = 0, len = clouds.length; i < len; i++) {
    const cloud = clouds[i];
    let { width, left } = cloud.getBoundingClientRect();
    let move = false;
    if (
      cloud.classList.contains("cloud1") ||
      cloud.classList.contains("cloud4")
    ) {
      move = loops % 4 === 1;
    }
    if (cloud.classList.contains("cloud3")) {
      move = loops % 4 === 1;
    }
    if (cloud.classList.contains("cloud2")) {
      move = loops % 2 === 1;
    }
    if (cloud.classList.contains("cloud5")) {
      move = loops % 3 === 1;
    }

    const styleLeft = Math.round(cloud.style.left.split("px")[0]);
    let nextPos = Math.round(left) - styleLeft - 2;
    if (Math.round(left) - 1 + width < 0) nextPos += innerWidth + width;
    if (move) cloud.style.transform = `translate3d(${nextPos}px, 0, 0)`;
  }
  loops++;
  requestAnimationFrame(anim);
};

const mouseUp = () => {
  clearInterval(heartTimer)
  heartTimer = null
  
  const open = new TimelineMax();
  open
    .to(eyes, 0.1, { scaleY: 1, transformOrigin: "center" }, 0)
    .to(fleck, 0.1, { opacity: 1 }, 0.05);

  const cheeks = document.getElementsByClassName("cheeks");
  const haltBlush = new TimelineMax();
  haltBlush
    .to(cheeks, 0.3, { opacity: 0 });
  
  // Resume
  blink.resume(3);
  window.removeEventListener('mouseup', mouseDown)
};

const colors = [
  "#fc3ad8",
  "#c53df7",
  "#f7e522",
  "#fc4c46",
  "#10f204",
  "#f21d2b",
  "#11e0dc",
  "#31a9f9"
];
const pickRandom = list => {
  const len = list.length;
  return list[Math.floor(Math.random() * len)];
};

const floatHeart = () => {
  const { left, width, top, height, bottom } = main.getBoundingClientRect();
  const sign = Math.round(Math.random()) ? -1 : 1;
  let heart = document.createElement("div");
  heart.classList.add("heart");
  document.body.appendChild(heart);
  
  const float = new TimelineMax({
    onComplete: function() {
      heart.remove();
      heart = null;
    }
  });
  const { innerWidth, innerHeight } = window;
  const vmin = Math.min(innerWidth, innerHeight) / 100;
  const heartLeft = Math.random() * width * 0.4 + width * 0.1 + left;
  const heartTop = Math.random() * height * .1 * sign + top
  const heartUp = (heartTop + 8 * vmin) / 4
  const heartHorizDelta = width * .05 * Math.random() + width * .03
  float
    .set(heart, { scale: 0.5, left: heartLeft, top: heartTop, color: pickRandom(colors) }, 0)
    .to(
      heart,
      heartTop / 80,
      {
        bezier: [
          { x: sign * heartHorizDelta, y: -heartUp },
          { x: 0, y: -heartUp * 2 },
          { x: sign * -1 * heartHorizDelta, y: -heartUp * 3 },
          { x: 0, y: -heartUp * 4 }
        ],
        ease: Linear.easeNone
      },
      0
    )
    .to(heart, 4, { scale: 1, color: pickRandom(colors) }, 0);
}

// Clicking on cloud <3
const mouseDown = (e) => {
  blink.pause();

  // Blink real quick
  const close = new TimelineMax();
  close
    .to(eyes, 0.08, { scaleY: 0.3, transformOrigin: "center" }, 0)
    .to(fleck, 0.05, { opacity: 0 }, 0)

  const cheeks = document.getElementsByClassName("cheeks");
  const blush = new TimelineMax();
  blush
    .to(cheeks, 0.05, { opacity: 0.15 })

  floatHeart()
  heartTimer = setInterval(function () {floatHeart()}, 300)
  
  window.addEventListener('mouseup', mouseUp)
};

initClouds();
requestAnimationFrame(anim);
window.addEventListener("resize", initClouds);
main.addEventListener("mousedown", mouseDown);
// document.body.classList.add('day')
// setTimeout(function () {
//   document.body.classList.remove('day')
// }, 3000)
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console