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 class="container">
  <button class="startPath1">Start Path 1</button>
  
  <button class="startPath2">Start Path 2</button>
  
    <div class="example1">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="560px" height="960px" viewBox="0 0 560 960" style="enable-background:new 0 0 800 500;" enable-background="new 0 0 560 960" xml:space="preserve">
<path class="path" style="fill:none;stroke:#ffffff;stroke-miterlimit:10;" d="M208.494,845.404c0,0-166.292-240.449-105.618-370.786
	c60.674-130.337,165.168-284.27,165.168-284.27s65.348-133.708,178.651,52.809s-110.112,171.91-144.943,166.292
	c-34.832-5.618-219.738-197.185-117.978-220.225s223.595,41.573,224.719,47.191s89.887,143.82,2.247,135.955
	s-143.82-89.888-143.82-89.888s-30.319-96.037,62.921-57.303s61.799,114.607,21.349,97.753S118.607,25.18,118.607,25.18"/>
</svg>
  <div class="emitter"></div>
</div>
  
  <div class="example2">
    <svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="560px" height="960px" viewBox="0 0 560 960" style="enable-background:new 0 0 800 500;" enable-background="new 0 0 560 960" xml:space="preserve">
<path class="path" style="fill:none;stroke:#ffffff;stroke-miterlimit:10;" d="M208.494,845.404c0,0-166.292-240.449-105.618-370.786
	c60.674-130.337,165.168-284.27,165.168-284.27s65.348-133.708,178.651,52.809s-110.112,171.91-144.943,166.292
	c-34.832-5.618-219.738-197.185-117.978-220.225s223.595,41.573,224.719,47.191s89.887,143.82,2.247,135.955
	s-143.82-89.888-143.82-89.888s-30.319-96.037,62.921-57.303s61.799,114.607,21.349,97.753S118.607,25.18,118.607,25.18"/>
</svg>
    <div class="emitter"></div>
  </div>


  
</div>
              
            
!

CSS

              
                body {
  font-family:sans-serif;
  margin:0; 
  background:#000;
}

.example2 {
  margin-left: 400px;
}

.emitter {
  background-color: green;
  width: 30px;
  height: 30px; 
  border-radius: 50%;
  position: absolute;
  top: 0;
 
}
.dot {
  background-color: #ffff66;
  border-radius: 50%;
  position: absolute;
  z-index:5000;
  pointer-events:none;
}

svg {
  position:absolute;
}
              
            
!

JS

              
                //points from SVG path run through Snap. BAM
var paths = document.getElementsByClassName("path");
    points = [];//holds our series of x/y values for anchors and control points


for(var i = 0; i<paths.length; i++) {
  points[i] = [];
  
  var data = Snap.path.toCubic(paths[i].getAttribute('d'))
      dataLength = data.length,
      pointsString = data.toString();

  // convert cubic data to GSAP bezier
  for (var j = 0; j < dataLength; j++) {
    var seg = data[j];
    if (seg[0] === "M") { // move (starts the path)
      var point = {};
      point.x = seg[1];
      point.y = seg[2];
      points[i].push(point);
    } else { // seg[0] === "C" (Snap.path.toCubic should return only curves after first point)
      for (var k = 1; k < 6; k+=2) {
        var point = {};
        point.x = seg[k];
        point.y = seg[k+1];
        points[i].push(point);
      }
    }
  }  
}

var emitters = document.getElementsByClassName("emitter");

var emitter1 = {
    emitterSize: 45,
    dotPool: [],
    dotIndex: 0,
    dotQuantity: 20,
    dotSizeMax: 8,
    dotSizeMin: 1,
    speed: -1,
    gravity: 0
};

var carrot = {
    emitterSize: 45,
    dotPool: [],
    dotIndex: 0,
    dotQuantity: 20,
    dotSizeMax: 8,
    dotSizeMin: 1,
    speed: -1,
    gravity: 0
};

var emitterObjs = [ emitter1, carrot ];

var tweens = [];

// Set each path
for(var i=0; i<emitters.length; i++) {  
  TweenLite.set(emitters[i], {x:points[i][0].x, y:points[i][0].y})
  //this tween calls the hideDots function when it is done. All dots with class ".emitter"+i will be hidden
  //start both tweens paused
  var tween = TweenMax.to(emitters[i], 8, {bezier:{type:"cubic", values:points[i]}, force3D:true, ease:Power0.easeNone, onComplete:hideDots, onCompleteParams:[".emitter" + i], paused:true});
  
  tweens.push(tween);
  
  TweenLite.set(emitterObjs[i], { width:emitterObjs[i].emitterSize, height:emitterObjs[i].emitterSize, xPercent:-50, yPercent:-50 });
  
  for (var j = emitterObjs[i].dotQuantity - 1; j >= 0; j--) {
    dot = document.createElement("div");
    //give each dot a class based on which emitter it belongs to "dot emitter0" or "dot emitter1"
    dot.className = "dot emitter" + i;
    TweenLite.set(dot, { xPercent:-50, yPercent:-50, force3D:true });
    document.body.appendChild(dot);
    emitterObjs[i].dotPool[j] = dot;
  }
  
  var explosion = new TimelineMax({ repeat: -1 }).call(shootDot, [[emitters[i], emitterObjs[i]]], null, 2 / emitterObjs[i].dotQuantity);
}

$(".startPath1").click(function(){
  tweens[0].restart();
  showDots(".emitter0")
})

$(".startPath2").click(function(){
  tweens[1].restart();
  showDots(".emitter1")
})

function shootDot(emit) {
  var elem = emit[0],
      emitter = emit[1];
    
  var angle, length, dot, size, bounds = elem.getBoundingClientRect();

  //create all the dots
    
  dot = emitter.dotPool[emitter.dotIndex++];
  if (emitter.dotIndex === emitter.dotQuantity) emitter.dotIndex = 0;
  size = getRandom(emitter.dotSizeMin, emitter.dotSizeMax);
  angle = Math.random() * Math.PI * 2; //random angle
  //figure out the maximum distance from the center, factoring in the size of the dot (it must never go outside the circle), and then pick a random spot along that length where we'll plot the point. 
  length = Math.random() * (emitter.emitterSize / 2 - size / 2); 
  //place the dot at a random spot within the emitter, and set its size.

  TweenLite.set(dot, {
    opacity:1,
    x:Math.cos(angle) * length + bounds.left + bounds.width / 2,
    y:Math.sin(angle) * length + bounds.top + bounds.height / 2,
    width:size,
    height:size
  });
  //this is where we do the animation...
  TweenLite.to(dot, 1 + Math.random(), {
    opacity:0,
    //if you'd rather not do physics, you could just animate out directly by using the following 2 lines instead of the physics2D:
    //x:Math.cos(angle) * length * 6, 
    //y:Math.sin(angle) * length * 6
  }, 0);
}


function getRandom(min, max) {
  return min + Math.random() * (max - min);
}


function hideDots(className) {
  TweenLite.set(className,  {visibility:"hidden"})
}


function showDots(className) {
  TweenLite.set(className,  {visibility:"visible"})
}

hideDots(".emitter0, .emitter1");


              
            
!
999px

Console