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

              
                
<div style="width: 700px; margin: 0 auto; overflow: hidden; background: rgba(255, 255, 255, 0.375);">
  <p>
    <button id="btn1">Play Timeline</button>
  </p>
  <div id="div1" style="transform: matrix(0.9901, -0.14037, 0.14037, 0.9901, 0, 0);"></div>
  <div id="div2" style="transform: matrix(0.99685, -0.07929, 0.07929, 0.99685, 0, 0);"></div>

  <div id="slider"><span id="op">0</span></div>
</div>
              
            
!

CSS

              
                body
{
	background:#222;
	margin:0;
}

#div1, #div2, #div3
{
	height:100px;
	width:100px;
	position:relative;
	border:solid 1px #fff;
	background:blue;
	margin:20px;
	border-radius:10px;
}

#div2
{
	background:red;
}

#div3
{
	background:green;
}

p
{
	margin:20px 0 0 20px;
}
              
            
!

JS

              
                var tl = new TimelineMax(),
	div1 = $("div#div1"),
	div2 = $("div#div2"),
	btn1 = $("button#btn1"),
	btn2 = $("button#btn2");

var processedAnimations = {
  "entrance": {
    "1250": [
      {
        "layer": "div1",
        "speed": 0.52,
        "time": 1250,
        "easing": "Power1.easeInOut"
      }
    ],
    "1260": [
      {
        "layer": "div2",
        "speed": 0.48,
        "time": 1260,
        "easing": "Power1.easeInOut"
      }
    ]
  },
  "exit": {
    
  }
};

var timelineElements = {};

function addProcessedAnimationsToTimeline(timeline)
{  
  if(processedAnimations)
  {
    for(var stageType in processedAnimations)
    {
      if(processedAnimations.hasOwnProperty(stageType))
      {
        var animationTimings = processedAnimations[stageType];

        if(animationTimings)
        {
          for(var time in animationTimings)
          {
            if(animationTimings.hasOwnProperty(time))
            {
              var animationItems  = animationTimings[time],
                  timeInSeconds   = time / 1000;

              if(animationItems && animationItems.length)
              {
                var animationItemLength = animationItems.length;

                for(var a = 0; a < animationItemLength; a++)
                {
                  var animationSettings   = animationItems[a],
                      animationName       = animationSettings.animation,
                      customSpeed         = animationSettings.speed,
                      customEasing        = animationSettings.easing,
                      layerId             = animationSettings.layer,
                      layerElement        = document.getElementById(layerId);

                  if(layerId && layerElement)
                  {
                    // Added temporarily instead of getting from animation properties in app
                    var processedSettings = {
                      "name":"zoomInCenter",
                      "type":"Zooming",
                      "stageType":"entrance",
                      "defaultDuration":0.4,
                      "defaultEasing":"Power1.easeInOut",
                      "series":[
                        {
                          "scale":0, 
                          "x": 750, 
                          "rotation": '-=360'
                        }
                      ]
                    };

                    if(processedSettings)
                    {
                      var defaultSet          = processedSettings.defaultSet || {rotation: 0},
                          duration            = customSpeed || processedSettings.defaultDuration,
                          easing              = customEasing || processedSettings.defaultEasing,
                          animationSeries;
                      
                      if(typeof timelineElements[layerId] == 'undefined')
                      {
                        var layerElementStyles = getElementStyles(layerElement);

                        timelineElements[layerId] = {
                          element:    layerElement,
                          layerId:    layerId,
                          styles:     layerElementStyles
                        };
                      }
                      
                      if(processedSettings.type == 'Text Effect')
                      {
                        // skipping this, not needed in demo
                      }
                      else
                      {
                        animationSeries = processedSettings.series;

                        if(defaultSet)
                        {
                          timeline.set(layerElement, defaultSet);
                        }
                        
                        for(var i = 0; i < animationSeries.length; i++)
                        {
                          var animation           = animationSeries[i],
                              animationDuration   = duration || animation.duration || .5,
                              animationEasing     = easing || animation.ease || 'Power1.easeInOut',
                              applyCustomEasing   = true;

                          try
                          {
                            var evaluatedEase = eval(animationEasing);
                          }
                          catch(e)
                          {
                            applyCustomEasing = false
                          }

                          if(applyCustomEasing)
                          {
                            // Apply easing if the eval() returned
                            animation = jQuery.extend(true, animation, {
                              ease: evaluatedEase
                            });
                          }

                          var tween;

                          // Disable immediate rendering of animation
                          animation.parseTransform = true;

                          // Set up TweenLite.from() for entrance animations
                          if(stageType == 'entrance')
                          {
                            
                            tween = TweenLite.from(layerElement, animationDuration, animation);
                          }
                          // Set up TweenLite.to() for exit animations
                          else if(stageType == 'exit')
                          {
                            tween = TweenLite.to(layerElement, animationDuration, animation);
                          }

                          // If tween is found, add tween to timeline
                          if(tween)
                          {
                            timeline.add(tween, timeInSeconds);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

function getElementStyles(element)
{
  element = jQuery(element).get(0);

  var styles = element.style;

  return {
    cssText:    styles.cssText,
    transform:  styles.transform
  };
}

function resetTimelineElements()
{
  if(Object.keys(timelineElements).length > 0)
  {
    for(var layerId in timelineElements)
    {
      if(timelineElements.hasOwnProperty(layerId))
      {
        var processedLayer = timelineElements[layerId];

        if(processedLayer.styles && processedLayer.styles.cssText)
        {
          jQuery(processedLayer.element).css({
            'cssText':      processedLayer.styles.cssText,
            'transform':    processedLayer.styles.transform
          });
        }
      }
    }
  }

  timelineElements = {};
}

function playAnimationTimeline()
{
  resetTimelineElements();
  
  if(tl)
  {
    tl.kill().clear();
  }
  
  tl = new TimelineMax({
    paused:     true,
    onComplete: onComplete
  });

  addProcessedAnimationsToTimeline(tl);
  
  tl.play();

  function onComplete()
  {
    
  }
}

btn1.click(function()
{
	playAnimationTimeline();
});
              
            
!
999px

Console