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 class="controls">
  <label for="speed">Speed</label>
  <input type="number" id="speed" value=5>
  <label for="ease">Ease</label>
  <select name="ease" id="ease">
    <option value="Power0.easeNone">None</option>
    <option value="Elastic.easeOut">Elastic Out</option>
    <option value="Elastic.easeIn">Elastic In</option>
    <option value="Elastic.easeInOut">Elastic In-Out</option>
    <option value="Bounce.easeOut">Bounce Out</option>
    <option value="Bounce.easeIn">Bounce In</option>
    <option value="Bounce.easeInOut">Bounce In-Out</option>
    <option value="Circ.easeOut">Circ Out</option>
    <option value="Circ.easeIn">Circ In</option>
    <option value="Circ.easeInOut">Circ In-Out</option>
    <option value="Cubic.easeOut">Cubic Out</option>
    <option value="Cubic.easeIn">Cubic In</option>
    <option value="Cubic.easeInOut">Cubic In-Out</option>
    <option value="Power0.easeOut">Power0 Out</option>
    <option value="Power0.easeIn">Power0 In</option>
    <option value="Power0.easeInOut">Power0 In-Out</option>
    <option value="Power1.easeOut">Power1 Out</option>
    <option value="Power1.easeIn">Power1 In</option>
    <option value="Power1.easeInOut">Power1 In-Out</option>
    <option value="Power2.easeOut">Power2 Out</option>
    <option value="Power2.easeIn">Power2 In</option>
    <option value="Power2.easeInOut">Power2 In-Out</option>
    <option value="Power3.easeOut">Power3 Out</option>
    <option value="Power3.easeIn">Power3 In</option>
    <option value="Power3.easeInOut">Power3 In-Out</option>
    <option value="Power4.easeOut">Power4 Out</option>
    <option value="Power4.easeIn">Power4 In</option>
    <option value="Power4.easeInOut">Power4 In-Out</option>
  </select>
  <button id="play">PLAY</button>
  <select name="image-selector" id="image-selector">
    <option value="plane">Plane</option>
    <option value="ball">Baseball</option>
  </select>
  <label for="backwards">Animate backwards?</label>
  <input type="checkbox" id="backwards" name="backwards"/>
  <label for="auto-rotate">Auto rotate?</label>
  <input type="checkbox" id="auto-rotate" name="backwards"/>
</div>
<div id="stage-container">
    <svg id="stage" width="1024" height="568" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 568">
    <foreignObject width="1024" height="568">
      <img id="ball" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/ball.png" alt="">
      <img id="plane" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/plane.png" alt="">    
    </foreignObject>
  </svg>
  <svg id="bez">
    <path class="path" d="M0 0 l800 79-800 59 800 66-800 62 800 71-800 77 400 51"/>
    <path class="reverse"/>
  </svg>
</div>
              
            
!

CSS

              
                .path
  stroke: red
  stroke-width: 5
  fill: none
svg
  display: block
  position: absolute
  top: 50px
  left: 100px
  &#stage
    background: white
    overflow: hidden
  &#bez
    background: transparent
    overflow: visible
foreignObject
  overflow: hidden
  img
    pointer-events: none
#data
  color: white
  position: fixed
  bottom: 10px
  left: 40px
  right: 40px
  text-align: center
body
  background-color: black
  font-family: monospace
  font-size: 1.4em
  color: white
#plane
  height: 67px
  display: block
#ball
  width: 100px
  display: none
// svg#bez g path
//   transform: scale(2.0)
// svg#bez g path:first-child
//   transform: scale(1.0)
path.reverse
  visibility: hidden
              
            
!

JS

              
                let pe = PathEditor.create(".path", {draggable:false, selected:true, handleSize: 10});

var stageContainer = document.getElementById('stage-container'),
    plane = document.getElementById('plane'),
    ball = document.getElementById('ball'),
    path = document.querySelector('path.path'),
    bezContainer = document.getElementById('bez'),
    bez = [], backBez = [], useBez = [];

function animateIt() {
  let dims = getXY({el: plane, path: path}), I = getImage();
  var t = I._gsTransform;
  t.x = 0;
  t.y = 0;
  let pd = path;
  bez = MorphSVGPlugin.pathDataToBezier(pd,{align:"relative", offsetX: dims.x, offsetY: dims.y});
  backBez = bez.slice(0);
  backBez.reverse();
  let autoRotate = $('#auto-rotate').prop('checked');
  useBez = $('#backwards').prop('checked') ? backBez : bez;
  let e = $('select#ease').val();
  let s = $('input#speed').val();
  TweenLite.to(I, s, {bezier:{
      values: useBez, type:"cubic", autoRotate: autoRotate
    }, 
    scaleY:"+=1", //just to trigger a value that we can set in the modifier below..
    modifiers:{
      scaleY:function(v) {
        return (t.rotation < 90 && t.rotation > -90) ? 1 : -1;
      }
    }, 
    ease: e, 
    onStart: hideBez, 
    onComplete: showBez});
}

function getImage() {
  let selector = $('#image-selector').val();
  if( selector == 'ball' ) {
    plane.style.display = 'none';
    ball.style.display = 'block';
    return ball;
  } else {
    plane.style.display = 'block';
    ball.style.display = 'none';
    return plane;
  }
}

function getXY(obj) {
  let I = obj.el;
  let bz = MorphSVGPlugin.pathDataToBezier(obj.path);
  let t = bz[0];
  let iDims = I.getBoundingClientRect();
  let X = (-1*iDims.width/2)+t.x,
      Y = (-1*iDims.height/2)+t.y;
  return {x: X, y: Y};
}

function hideBez() {
  $('svg#bez').hide();
}

function showBez() {
  $('svg#bez').show();
}

function init() {
  // flip the plane around so it's going in the right direction
  let dims = getXY({el: plane, path: path});
  TweenMax.set(plane,{transformOrigin: 'center center', x: dims.x, y: dims.y});
  dims = getXY({el: plane, path: path});
  TweenMax.set(ball,{transformOrigin: 'center center', x: dims.x, y: dims.y});
}

$('#play').on('click', function(){
  animateIt();
});

init();

              
            
!
999px

Console