Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                <div id="container" class="container">
 <svg id="particles"></svg>
</div>
              
            
!

CSS

              
                /* **************************************** */
/* Default CSS styles being imported from:
/* https://codepen.io/dipscom/pen/RWXPBB
/* **************************************** */
.container {
 padding: 0;
}


/* ****************** */
/* Notes and reminders
/* ****************** */



/* ****************** */
/* Local CSS styling
/* ****************** */
svg {
 margin: 0;
 display: block;
 width: 100%;
 height: 600px;
}

.dot {
 // visibility: hidden;
}
              
            
!

JS

              
                var container = document.getElementById("container");
var holder = document.getElementById("particles");
var hW = container.offsetWidth;
var hH = container.offsetHeight;
var particles = [];
var ttlParticles = 126;
var minSize = 2;
var maxSize = 20;
var hue = 0;
var hueStep = 360 / ttlParticles;


// Create a bunch of circles to animate
for(var i=0; i < ttlParticles; i++) {
  
 var dot = document.createElementNS(holder.namespaceURI, 'ellipse');
 // Place all the dots at the center of the SVG
 dot.setAttribute('cx',(hW*0.5));
 dot.setAttribute('cy',(hH*0.5));
 // Initial radius of the elipse does not matter, is only a placeholder
 dot.setAttribute('rx',10);
 dot.setAttribute('ry',10);
 // Give each a random color
 dot.setAttribute('fill', getColor());
 dot.setAttribute('class', 'dot');
 // Add the circle into an array for later manipulation
 particles.push(dot);
 // Then add it to the holder SVG
 holder.appendChild(dot);
 
}

// Reorder the circles, so that the ones that are on top (created last) animate first
particles.reverse();

//
// Move each particle
var tl = new TimelineLite({onComplete:loop});

function buildTL() {
 tl.add("Start")
  // We have to set the radius to 0 right at the start
  .set('.dot', {attr:{rx:0, ry:0}})

  // Go somewhere random from the center
 .staggerTo(particles, 1, {
  ease:Power4.easeInOut,
  transformOrigin:"center",
  autoAlpha:1,
  rotation:"+=720",
  cycle:{
   x:function() {
    return randomFloat(-(hW*0.5 - 20), (hW*0.5 - 20));
   }, 
   y:function() {
    return randomFloat(-(hH*0.5 - 20), (hH*0.5 - 20));
   },
   attr:function() {
    return getRadius();
   }
  }
 }, 0.01, "Start")


 .add("DotsOut")
 
 // Now, go back to the center
 .staggerTo('.dot', 6, {
   ease:Power2.easeInOut,
   transformOrigin:"center",
   cycle:{
    bezier:getBezierArray(Math.ceil(randomFloat(3,9)))
  }
 }, 0.05, "DotsOut")

 .staggerTo('.dot', 1, {
  ease:Power2.easeInOut,
  attr:{ry:2}
 }, 0.05, "DotsOut")

 .staggerTo('.dot', 6, {
  ease:Power2.easeIn,
  attr:{rx:2},
 }, 0.05, "DotsOut" )
 
 
 .add("End")
 
 // A little flourish at the end
 .staggerTo('.dot', 1, {
  attr:{
   rx:0, 
   ry:0
  }, 
  cycle:{
   ease:function(i) {
    return Back.easeIn.config(i*2); 
   }
  }
 }, 0.01, "End")
 
 .staggerTo('.dot', 0.9, {
  autoAlpha:0,
  ease:Power2.easeOut
 }, 0.008, "End" )

};






/* Timeline related functions */
function loop() {
 // Kill the timeline, erasing all values and callback, ready for garbage collection
 tl.kill();
 // Rebuild the animation so we can have a different motion at every repeat
 buildTL();
};





/* Helpers */
function getRadius() {
 
 var value = randomFloat(minSize, maxSize);
 
 return {
  rx: value,
  ry: value
 }
};




function getBezierArray(num) {
 // return an array that contains an array that contains a number of objects
 var bezierArr = [];
 
 for( var i=0; i < num; i++ ) {
  var obj = {
   curviness:1.25,
   autoRotate:true,
   values:getBezierPoints(randomFloat(3,6))
  }

  bezierArr.push(obj);
 }
  
 return bezierArr;
 
};




function getBezierPoints(num) {

 var bezierPoints = [];
 
  for(var i=0; i < num; i++) {
   var bezierObj = {
     x:randomFloat(-(hW*0.5), (hW*0.5)),
     y:randomFloat(-(hH*0.5), (hH*0.5))
   };
   
   bezierPoints.push(bezierObj);
  }
 
  // At the end, move the dots back to their starting point
  bezierPoints.push({x:0, y:0});
  
 
 return bezierPoints;
 
};




function randomFloat(min, max) {

 return min + Math.random()*(max-min);

};




function getColor() {
 
 var color = 'hsla(' + hue + ', 50%, 45%, 1)';
 
 hue += hueStep; 
 // console.log(color, " ", hueStep);

 return color;

}



              
            
!
999px

Console