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

              
                <svg id="db-anim" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1110 300" preserveAspectRatio="xMidYMin meet">
    
  <g class="paths">
    <path id="path-1" class="st0" d="M500 300V100h-300V0"/>
    <path id="path-2" class="st0" d="M500 300V100h-100V0"/>
    <path id="path-3" class="st0" d="M500 300V100h100V0"/>
    <path id="path-4" class="st0" d="M500 300V100h300V0"/>
  </g>
  
  <g class="paths02">
    <path id="pathA" class="alt-path" d="M500 300V300h-300V400"/>
    <path id="pathB" class="alt-path" d="M500 300V300h-100V400"/>
    <path id="pathC" class="alt-path" d="M500 300V300h100V400"/>
    <path id="pathD" class="alt-path" d="M500 300V300h300V400"/>
  </g>
  
  <g>
    <circle class="circle circle-1" cx="0" cy="0" r="10"/>
    <circle class="circle circle-2" cx="0" cy="0" r="10"/>
    <circle class="circle circle-3" cx="0" cy="0" r="10"/>
    <circle class="circle circle-4" cx="0" cy="0" r="10"/>
  </g>
  
</svg>

              
            
!

CSS

              
                #db-anim {
  position: fixed;
  width: 100%;
  height: 100%;
}

.st0, .alt-path {
  fill: none;
  stroke: #424142;
  stroke-width: 2;
  stroke-miterlimit: 10;
}

.circle {
  fill-opacity: 0.5;
  opacity: 0;
}

.circle-1 {
  fill: #d81b60;
}

.circle-2 {
  fill: #4caf50;
}

.circle-3 {
  fill: #2196F3;
}

.circle-4 {
  fill: #ff9800;
}

              
            
!

JS

              
                console.clear();

var numVariations = 10;
var pathOrder = [];
var pathLists = [];

var mainTl = new TimelineMax();

// Create an array of all the starting path values
var startPaths = $(".st0").toArray().map(function(element) {
  return MorphSVGPlugin.pathDataToBezier(element).reverse();
})

// Create an array of all the alternate path values
var altPaths = $(".alt-path").toArray().map(function(element) {
  var path = MorphSVGPlugin.pathDataToBezier(element);
  
  // Shift removes first point from the array
  // We don't need it as we will be combining this path with a 
  // start path
  path.shift();
  return path;
});

// Create an array of the path order (indexes) [0,1,2,3]
// And add an array to the pathLists array to hold
// the different path variations. pathLists will end up
// being an array of arrays
for (var i = 0; i < startPaths.length; i++) {
  pathOrder.push(i);
  pathLists.push([])
}

// Might be confusing. Shuffles the path order, then joins a 
// start path and alternate path together to create a random path variation
for (var i = 0; i < numVariations; i++) {
  
  shuffle(pathOrder);
  
  pathLists.forEach(function(pathList, index) {
    var path = startPaths[index].concat(altPaths[pathOrder[index]]);
    pathList.push(path)
  });
}

$(".circle").each(function(index, circle) {
  
  var motionPaths = pathLists[index];
    
  // Double index here because it's an array of arrays
  var start = motionPaths[0][0];
  
  TweenLite.set(circle, {
    autoAlpha: 1,
    x: start.x,
    y: start.y
  });
  
  var tl = new TimelineMax({
    repeat: -1
  });
  
  motionPaths.forEach(function(motionPath) {
    
    tl.set(circle, {
      x: start.x, 
      y: start.y
    })
    .to(circle, random(1.5, 2), {
      bezier: {
        values: motionPath,
        type: "cubic"
      },
      ease: Linear.easeNone
    })    
  })
  
  mainTl.add(tl, 0);
});

function random(min, max) {
  if (max == null) { max = min; min = 0; }
  if (min > max) { var tmp = min; min = max; max = tmp; }
  return min + (max - min) * Math.random();
}

function shuffle(array) {
  for (var i = array.length - 1; i > 0; i--) {
    var j = Math.floor(Math.random() * (i + 1));
    var temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
  return array;
}
              
            
!
999px

Console