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

              
                <script src="https://cdn.rawgit.com/web-animations/web-animations-js/master/web-animations.min.js"></script>
<div id="clouds">
</div>
              
            
!

CSS

              
                html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}
#clouds {
  background-color: rgb(15, 13, 63);
  background-image: linear-gradient(#3b0097, #e03a85);
  height: 100%;
  cursor: pointer;
  overflow: hidden;
}
.cloud {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: white;
  transform: translate(-20px,-20px);
  box-shadow: 0 0 24px black;
  pointer-events: none;
}
.cloud:hover {
  cursor: pointer;
}
.cloud::before,.cloud::after {
  content: "";
  position: absolute;
  width: 100%;
  top: 15%;
  height: 80%;
  background: white;
  border-radius: 50%;
}
.cloud::before {
  left: -8px;
}
.cloud::after {
  right: -8px;
}
              
            
!

JS

              
                "function"!=typeof Math.sign&&(Math.sign=function(a){a=+a;return 0===a||isNaN(a)?a:0<a?1:-1});

// exists because Mobile Safari re-uses touch events.
function cloneTouchList(tl) {
	if (!tl) {
    return null;
  }
  var out = [];
  for (var i = 0; i < tl.length; ++i) {
    var t = tl[i];
	  out.push({
      clientX: t.clientX,
      clientY: t.clientY,
      offsetX: t.offsetX,
      offsetY: t.offsetY,
      screenX: t.screenX,
      screenY: t.screenY
    });
  }
  return out;
};

var CLOUD_COUNT = 80;

function startClouds() {
  var parent = document.getElementById('clouds');
  var width = window.innerWidth;
  var height = window.innerHeight;
  var players = [];

  function buildCloud(i) {
    var cloud = document.createElement('div');
    cloud.className = 'cloud';
    parent.appendChild(cloud);

    var start = -40;
    var end = width + 40;
    var y = Math.random() * height;
  
    var player = cloud.animate([
      {transform: 'translate(' + start + 'px, ' + y + 'px)'},
      {transform: 'translate(' + end + 'px, ' + y + 'px)'}
    ], {
      duration: 10000,
      delay: i * 200,
      endDelay: i * 200,
      easing: 'ease-in-out',
      fill: 'both',
      iterations: Infinity
    });
    players.push(player);
  };

  for (var i = 0; i < CLOUD_COUNT; ++i) {
		buildCloud(i);
  }

  var startEvent, startEventTime;

  /** start event handler */
  function onStart(event) {
    startEvent = event;
    startEvent._touches = cloneTouchList(startEvent.touches);
    startEventTime = players[0].currentTime;
    console.info(startEventTime, 'start');
    players.forEach(function(p) { p.pause(); });
  }
  document.addEventListener('touchstart', onStart);
  document.addEventListener('mousedown', onStart);

  /** move handler */
  function onMove(event) {
    if (!startEvent) return;
    if (event.type == 'touchmove') event.preventDefault();
    var delta = eventDelta(startEvent, event);
    var updateTime = startEventTime + delta;
    console.debug('currentTime', updateTime);
    players.forEach(function(p) { p.currentTime = updateTime; });
  }
  document.addEventListener('touchmove', onMove);
  document.addEventListener('mousemove', onMove);

  /** end handler */
  function onEnd(event) {
    if (!startEvent) return;
    var playbackRate = Math.sign(eventDelta(startEvent, event));
    console.info(startEventTime, 'up', playbackRate);
    players.forEach(function(p) {
      p.playbackRate = playbackRate;
      p.play();
    });
    startEvent = null;
  }
  document.addEventListener('touchend', onEnd);
  document.addEventListener('mouseup', onEnd);
}

function eventDelta(startEvent, event) {
  if (startEvent.type == 'touchstart') {
	  var distance = startEvent._touches[0].screenX - event.changedTouches[0].screenX;
    return distance * 4;  // make touch event feel longer
  } else {
    return startEvent.clientX - event.clientX;
  }
}

document.addEventListener('DOMContentLoaded', startClouds, false);
              
            
!
999px

Console