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

              
                
<!-- annotaion in js -->

<div id="stage">

<svg id="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 600">
  <g id="bg">
    <rect width="1000" height="600" />
  </g>
  <g id="bug1" class="bug cls-1">
    <g>
      <rect class="cls-2" x="538.61672" y="240" width="52" height="58" />
      <polygon class="cls-2" points="630.617 240 630.617 326.834 713.561 240 630.617 240" />
      <polygon class="cls-2" points="538.617 406 498.617 406 498.617 240 476.217 240 286.439 440 523.778 440 590.617 370.043 590.617 328 538.617 328 538.617 406" />
    </g>
  </g>
  <g id="bug2" class="bug cls-3">
    <g>
      <rect class="cls-2" x="252.82421" y="205" width="44.2" height="49.3" />
      <polygon class="cls-2" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
      <polygon class="cls-2" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
    </g>
  </g>
  <g id="bug3" class="bug cls-4">
    <g>
      <rect class="cls-2" x="827.0317" y="270" width="36.4" height="40.6" />
      <polygon class="cls-2" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
      <polygon class="cls-2" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
    </g>
  </g>
  <g id="bug4" class="bug cls-1">
    <g>
      <rect class="cls-2" x="827.0317" y="270" width="36.4" height="40.6" />
      <polygon class="cls-2" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
      <polygon class="cls-2" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
    </g>
  </g>
  <g id="bug5" class="bug cls-3">
    <g>
      <rect class="cls-2" x="252.82421" y="205" width="44.2" height="49.3" />
      <polygon class="cls-2" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
      <polygon class="cls-2" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
    </g>
  </g>
  <g id="bug6" class="bug cls-1">
    <g>
      <rect class="cls-2" x="827.0317" y="270" width="36.4" height="40.6" />
      <polygon class="cls-2" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
      <polygon class="cls-2" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
    </g>
  </g>
  <g id="bug7" class="bug cls-4">
    <g>
      <rect class="cls-2" x="252.82421" y="205" width="44.2" height="49.3" />
      <polygon class="cls-2" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
      <polygon class="cls-2" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
    </g>
  </g>
  <g id="bug8" class="bug line cls-5">
    <g>
      <rect class="cls-5" x="827.0317" y="270" width="36.4" height="40.6" />
      <polygon class="cls-5" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
      <polygon class="cls-5" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
    </g>
  </g>
  <g id="bug9" class="bug line cls-6">
    <g>
      <rect class="cls-6" x="252.82421" y="205" width="44.2" height="49.3" />
      <polygon class="cls-6" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
      <polygon class="cls-6" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
    </g>
  </g>
</svg>

</div><!-- /#stage -->

              
            
!

CSS

              
                /* annotation in js */

body {
  overflow: hidden;
  background-color: #222;
  margin: 0;  padding: 0;
}
#stage {
	position: relative;  top: 5%;  left: 0;
	height: 85%;  width: 100%;
	background-color: #111;
	border: 0;
	/* pointer-events: none; */
}
#svg {
	background-color: #111;
}

/* --- svg defs styles --- */

.cls-2 { fill: #f2a42c; }

.cls-1 { opacity: 0.3; }
.cls-3 { opacity: 0.3; }
.cls-4 { opacity: 0.3; }
.cls-3 .cls-2 { fill: #bbc9ef; }

.cls-5, .cls-6 {
  fill: none;
  stroke-width: 0.47px;
}
.cls-5 { stroke: #cbd9df; }
.cls-6 { stroke: #9aa8ad; }

#bug8 rect,polygon, #bug9 rect,polygon { stroke-width: 0.37px; }

.bug { position: absolute;  opacity: 0; }


              
            
!

JS

              
                console.clear();

// my first GSAP amimation... whee!!  great stuff.
//  dreamy background using the bug from a client logo.
//  runs infinitely... when a layer dies it spawns a new one.
//  works best in Firefox, half the CPU of Safari or Chrome.

// SVG exported from Illustrator, hence funky class names.
//  hey, it's my first.

/* change this next value sensibly... */

var bcount = 5;  // number of layers... 1 to 9
  // "bcount" = bug count, i.e. logo bugs preloaded in the SVG

// layers should fade in slowly and float up the screen,  
//  slowly fading back out to zero on exit.

// what I'm testing is where the problem begins where
//  layers disappear before finishing their timelines,
//  i.e. before they fade out to zero.  It's not a disaster,
//  still looks cool, but would like to isolate / optimize.

// bcount 1 works perfectly.  layers always fade out to 0.
// bcount 2 nearly all good, very occasional disappearence.
// bcount 3 start to get disappearing layer behavior
// ... little difference from ...
// bcount 9 disappearing often but looks cool. ;-)

// This may just be an observation of where things start to 
//  break down when you pile on computationally intensive layers. 
//  still, can't help noticing how well 9 layers performs.
//  not significantly more CPU than 3 layers.  nice.

// helpers round and rnd() below
//  rnd() is for easy syntax of rnd(min, max, decimal precision)

if (bcount > 9) bcount = 9;
if (bcount < 1) bcount = 1;

function bugIn( n ) {
	var el = $('#bug'+ n ), 
		tl = new TimelineLite(), 
		scl  = rnd(1.9, 3.2, 3),  // scale
		dur  = rnd(1.5, 4, 3),   // master duration unit
      
      totalDur = dur * 3,  // x3 should work
        // increasing this doesn't seem to help
      
		xpos = rnd(-511, n * 30 - 130, 0),  // init x
		ypos = rnd(170, 101, 0),            // init y
		omax = rnd(0.11, 0.17, 3),    // opacity max
		pps  = rnd(-47, -13, 0);      // speed, pixels per second
    
	// put longest tween, i.e. position, first then add opacity ones
	tl.set( el, { opacity: 0, scale: scl, x: xpos, y: ypos })
	   .to( el, totalDur, { y: ypos + (pps * dur * 3), ease: Power0.easeNone } )
	   .to( el, dur, { opacity: omax, ease: Power0.easeNone }, 0)
	   .to( el, dur, { opacity: 0, ease: Power0.easeNone }, dur * 2);
	
	return tl;
}

var bnum = 0;  // counter
function newBug(bnum) {
  
  console.log("bnum", bnum);
  
	// bnum = ( ++bnum - 1 ) % bcount + 1;  // keep counting from 1 to bcount
	var tm = new TimelineMax({ 
    onComplete: newBug,
    onCompleteParams: [bnum]
  });
	tm.add( bugIn( bnum ));
	return tm;
}


// start 'em up...
// while (bnum < bcount) newBug();

for (var i = 0; i < bcount; i++) {
  newBug(i + 1);
}

// - - - - - - - -
// helpers

function round(val, dec) {
    var mul = Math.pow(10, dec || 0);
    return Math.round( parseFloat( val ) * mul) / mul;
}
function rnd(min, max, dec) {
	dec != 0;
	return round( Math.random() * (max - min) + min, dec );
}

TweenLite.onOverwrite = function(overwritten, overwriting, target, props) {
  console.log("tween that was overwritten", overwritten);
  console.log("tween that did the overwriting", overwriting)
  console.log("the target of the overwritten tween", target);  
  console.log("properties that were overwritten", props);
}
              
            
!
999px

Console