css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href='//fonts.googleapis.com/css?family=Signika+Negative:300,400' rel='stylesheet' type='text/css'>

<div class="wrapper">
  <h1>Take Control of all GSAP Animations</h1>
  <h2>The power of TimelineLite.exportRoot()</h2>

  <p>In the animation below the hearts, bubbles, truck, and hill are all being animated by a variety of loose timelines and tweens that are not nested in a parent timeline. TimelineLite.exportRoot() will return a single timeline that holds all the active animations making it easy to control all the animations at once.</p>
  <div class="container">
  <svg class="mainSVG" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 200 600 200">
    <defs>
<filter id="goo">
        <feGaussianBlur in="SourceGraphic" stdDeviation="1" result="blur" />
        <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 12 -1.9" result="cm" />

      </filter> 
     
<g id="bubble" stroke="#F3F1E2">
	
		<ellipse fill="none" stroke-width="1" stroke-miterlimit="10" cx="8" cy="8" rx="7" ry="7"/>
	<path fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="M3.39,8
		c0.07-0.84,0.35-1.68,0.87-2.42c0.5-0.71,1.15-1.25,1.89-1.61"/>
</g>      

<path id="heart" fill="none" stroke="#F3F1E2" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="
	M11.58,3.55c0,4.16-4.32,8.04-5.54,8.04S0.5,7.7,0.5,3.55c0-1.68,1.36-3.05,3.05-3.05c1.03,0,1.94,0.51,2.49,1.3
	c0.55-0.78,1.46-1.3,2.49-1.3C10.22,0.5,11.58,1.86,11.58,3.55z M3.99,2.25c-0.86,0-1.72,0.78-1.78,1.86"/>    
    <g id="pop" class="pop" fill="none" stroke="#F3F1E2" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" opacity="0">    
	<circle cx="18.22" cy="17.89" r="0" stroke="#F3F1E2" fill="none"/>
		<line x1="18" y1="10.5" x2="18" y2="0.5"/>
	
		<line x1="18" y1="25.5" x2="18" y2="35.5"/>
	
		<line x1="25.5" y1="18" x2="35.5" y2="18"/>
	
		<line x1="10.5" y1="18" x2="0.5" y2="18"/>
</g>     
    </defs>
  
    <g id="follower" ></g>
    
    <path id="waveyPath" fill="none" stroke="none" stroke-width="3.5" stroke-linecap="round" stroke-miterlimit="10" d="M300,338
	c100,0,100,36,199.99,36c100,0,100-36,200-36c100,0,100,36,200,36c100,0,100-36,200-36c100,0,100,36,200.01,36s100-36,200.01-36" />
    <g id="movingPath">
    <path id="filledMovingPath" fill="#69B565" d="M2300.5,338c-100,0-100,36-200.01,36
	c-100,0-100-36-200.01-36c-100,0-100,36-200,36c-100,0-100-36-200-36c-100,0-100,36-200,36c-100,0-100-36-199.99-36
	c-100,0-100,36-200.01,36s-100-36-200.01-36c-100,0-100,36-200,36c-100,0-100-36-200-36c-100,0-100,36-200,36
	c-100,0-100-36-199.99-36v423h2400V338z"/>
<path class="movingPath" fill="none" stroke="#F3F1E2" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M-100,338
	c100,0,100,36,199.99,36c100,0,100-36,200-36c100,0,100,36,200,36c100,0,100-36,200-36c100,0,100,36,200.01,36s100-36,200.01-36
	c100,0,100,36,199.99,36c100,0,100-36,200-36c100,0,100,36,200,36c100,0,100-36,200-36c100,0,100,36,200.01,36
	c100,0,100-36,200.01-36" />
    </g>
    <g id="jumpingLorry">
      <g id="movingLorry">
        <g id="lorryGroup" fill="none" stroke="#F3F1E2" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10">
          
          <path  d="M53.58,34.5		H48v-24h12.24c2.2,0,4.34,1.76,4.76,3.92l1.56,7.9l1.96,0.78c1.93,0.77,3.49,3.07,3.49,5.15v4.25c0,1.1-0.89,2-2.01,2h-3.26h-0.3
		C65.94,31.38,63.25,29,60,29S54.06,31.38,53.58,34.5z" />

          <line x1="1.5" y1="34.5" x2="10.5" y2="34.5" />
          <path fill="#3D933A" stroke="#F3F1E2" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M34.41,34.5
		H48v-29c0-2.2-1.79-4-4.01-4H9.01C6.79,1.5,5,3.29,5,5.5v29h6.65c0.81-5.81,5.59-10.28,11.38-10.28S33.6,28.69,34.41,34.5z" />
          <path d="M53.25,15.53h3.66
		c1.58,0,3.02,1.19,3.22,2.65l0.1,0.7c0.2,1.46-0.92,2.65-2.5,2.65h-4.48V15.53z" />
          <path d="M34.53,36.24
		c0-6.64-5.15-12.02-11.5-12.02c-6.35,0-11.5,5.38-11.5,12.02" />
          
          <g id="wheelL">

            <circle cx="23.03" cy="35.72" r="6.5" />
            <circle fill="#F3F1E2" stroke="none" cx="23" cy="35.5" r="1" />
          </g>
          <g id="wheelR">

            <circle cx="60" cy="35.5" r="6.5" />
            <circle fill="#F3F1E2" stroke="none" cx="60" cy="35.5" r="1" />
          </g>
        </g>
      </g>
    </g>
    
  </svg>


</div>
  <span style="font-family:sans-serif; color:#ddd; font-size:14px">illustration and animation by Chris Gannon</span>
  <div class="nav" style="text-align:left;  position:relative; top:-10px;">
    
    <button id="pause">pause</button>
    <button id="play">play</button>
  </div>
  
</div>

<div class="brandBar">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/GreenSock-logo-text-outlines.svg"></div>
            
          
!
            
              /* Global styles come from external css https://codepen.io/GreenSock/pen/JGaKdQ*/



.container{
  overflow:hidden;
  position:relative;
  width:800px;
  background:#3D933A;
  
}

svg{
  
  visibility:hidden;
  overflow:hidden;
}

p {
  width:800px;
}

#play {
  visibility:hidden;
}
            
          
!
            
              //From 7 Hidden Gems of GSAP (Net Magazine)
//Read full article: https://medium.com/net-magazine/7-hidden-gems-of-the-greensock-animation-platform-4fb71389f6ca#.t6xniz19i

//scroll down to the bottom to see code pertinent to the exportRoot() functionality

var xmlns = "http://www.w3.org/2000/svg",
  xlinkns = "http://www.w3.org/1999/xlink"
select = function(s) {
    return document.querySelector(s);
  },
  selectAll = function(s) {
    return document.querySelectorAll(s);
  },
  container = select('.container'),
  mainSVG = select('.mainSVG'),
  waveyPath = select('#waveyPath'),
  pop = select('#pop'),
  follower = select('#follower'),
  movingPath = select('#movingPath'),
  jumpingLorry = select('#jumpingLorry'),
  movingLorry = select('#movingLorry'),
  lorryGroup = select('#lorryGroup'),
  particleContainer = select('#particleContainer'),
  //particleTypeArray = ['#flake1', '#flake2', '#flake3', '#star','#heart'],
  particleTypeArray = ['#bubble', '#heart'],
  particleColorArray = ['#F3F1E2', '#B51541'],
  particlePool = [],
  popPool = [],
  numParticles = 270,
  particleCount = 0

//center the container cos it's pretty an' that

TweenMax.set('svg', {
  visibility: 'visible',
  y:10
  
})

TweenMax.set(lorryGroup, {
  transformOrigin: '50% 100%'
})
TweenMax.set(jumpingLorry, {
  transformOrigin: '50% 50%',
  rotation: 0
})
TweenMax.set(follower, {
  x: 0,
  y: 0
})
TweenMax.set(pop, {
  opacity:0
  
})
var waveyPathBezier = MorphSVGPlugin.pathDataToBezier(waveyPath.getAttribute('d'), {
  offsetX: -(lorryGroup.getBBox().width / 2),
  offsetY: -(lorryGroup.getBBox().height) - waveyPath.getAttribute('stroke-width')
})

var tl = new TimelineMax({
  repeat: -1,
  onUpdate: playParticle
});
tl.to(lorryGroup, 6, {
    bezier: {
      type: "cubic",
      values: waveyPathBezier,
      autoRotate: true
    },
    ease: Linear.easeNone
  })
  .to([movingPath, movingLorry], 6, {
    x: -1200,
    ease: Linear.easeNone
  }, '-=6')

var jumpTl = new TimelineMax();
jumpTl.to(lorryGroup, 0.16, {
  //y:-6,
  scaleY: 0.97,
  scaleX: 1.03,
  repeat: -1,
  ease: Linear.easeNone,
  yoyo: true
})

function createParticlePool() {

  var i = numParticles,
    p, popClone;
  while (--i > -1) {

    p = document.createElementNS(xmlns, 'use');
    popClone = pop.cloneNode(true);
    //pop.setAttributeNS(xlinkns, "xlink:href", '#pop');
    p.setAttributeNS(xlinkns, "xlink:href", particleTypeArray[i % particleTypeArray.length]);
    follower.appendChild(p);
    follower.appendChild(popClone);

    p.setAttributeNS(null, 'stroke', particleColorArray[i % particleColorArray.length]);
    //popClone.setAttributeNS(null, 'opacity', 1);
    //p.setAttribute('class', "particle");
    particlePool.push(p);
    popPool.push(popClone);
    TweenMax.set([p, popClone], {
      transformOrigin: '50% 50%',
      alpha:1
        //x:300,
        //y:follower._gsTransform.y
    })
    
    
    TweenMax.set([p], {
      scale: 0
    })

  }

}

//ScrubGSAPTimeline(tl);

function playParticle() {
  //console.log(particleCount%250 == 1)

  if (particleCount % 13) {
    particleCount++;
    checkParticleCount();
    return;
  }

  var p = particlePool[particleCount];
  TweenMax.set(p, {
    x: 260,
    y: lorryGroup._gsTransform.y + 12,
    //scale:0,
    alpha: 1
  })

  var s = randomBetween(5, 10) / 10;
  TweenMax.to(p, 0.46, {
    scaleX: s,
    ease: Elastic.easeOut.config(1, 0.83)
  })
  TweenMax.to(p, 0.6, {
    scaleY: s,
    ease: Elastic.easeOut.config(1, 0.4)
  })
  TweenMax.to(p, randomBetween(1, 2), {
    //paused:true,
    physics2D: {
      velocity: randomBetween(30, 165),
      angle: randomBetween(-180, -160),
      gravity: randomBetween(-130, -17)
    },
    onComplete: function(p) {
      TweenMax.set(p, {
        scale: 0
      })

      createPop(p);
    },
    onCompleteParams: [p]
  });

  particleCount++;

  checkParticleCount();
}

function createPop(p) {

  var popTl = new TimelineMax(),
    popClone = popPool[particleCount],
    popLines = popClone.getElementsByTagName('line'),
    popCircle = popClone.getElementsByTagName('circle');
  TweenMax.set(popClone, {
    x: p._gsTransform.x - 10,
    y: p._gsTransform.y - 10,
    rotation: 45
  })

  TweenMax.set(popCircle, {
    alpha: 1,
    attr: {
      r: 0
    }
  })
  popTl.set(popLines, {
      drawSVG: '0% 0%'

    })
    .to(popLines, 0.3, {
      drawSVG: '0% 20%',
      ease: Linear.easeNone
    })
    .to(popLines, 0.6, {
      drawSVG: '80% 100%',
      ease: Linear.easeNone
    })
    .to(popLines, 0.2, {
      drawSVG: '105% 105%',
      ease: Linear.easeNone
    })
    .to(popClone, 1, {
      x: '-=20',
      y: '-=20',
      scale: 0.5,
      ease: Linear.easeNone
    }, '-=' + popTl.duration())
    .to(popCircle, 1, {
      attr: {
        r: 6
      },
      alpha: 0,
      ease: Expo.easeOut
    }, '-=' + popTl.duration());

  popTl.timeScale(1.6)
}

function checkParticleCount() {
  particleCount = (particleCount >= numParticles) ? 0 : particleCount;
}

tl.timeScale(1);
createParticlePool();
 //ScrubGSAPTimeline(tl);
function randomBetween(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}


//this code demonstrates how exportRoot() works

var globalTimeline = new TimelineLite(); //will store all animations

//when the pause button is clicked export all animations 
//to the globalTimeline and pause
document.getElementById("pause").onclick = function() {
  if(!globalTimeline.paused()){
    TweenLite.set("#play", {autoAlpha:1})
    globalTimeline = TimelineLite.exportRoot();
    globalTimeline.pause();
  }  
}


document.getElementById("play").onclick = function() {
    globalTimeline.resume();
}


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console