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="buttons-wrapper">
  <button class="play">Play</button>
  <button class="pause">Pause</button>
</div>
<div class='menus'>
  <label for="set-start">Set start time: </label>
  <select name="set-start" id="set-start">
    <option value="0">0</option>
    <option value="0.5">0.5 second</option>
    <option value="1">1 seconds</option>
    <option value="1.5">1.5 seconds</option>
    <option value="2">2 seconds</option>
  </select>
  <label for="set-tween">Set tween time: </label>
  <select name="set-tween" id="set-tween">
    <option value="0.5" selected>0.5 seconds</option>
    <option value="1">1 second</option>
    <option value="1.5">1.5 seconds</option>
    <option value="2">2 seconds</option>
    <option value="2.5">2.5 seconds</option>
  </select>
  <label for="change-direction">Change <span style="  font-style: italic;">from</span> direction: </label>
  <select name="change-direction" id="change-direction">
    <option value="inTop">Top</option>
    <option value="inTopRight">Top Right</option>
    <option value="inRight">Right</option>
    <option value="inBottomRight">BottomRight</option>
    <option value="inBottom">Bottom</option>
    <option value="inBottomLeft">Bottom Left</option>
    <option value="inLeft">Left</option>
    <option value="inTopLeft">Top Left</option>
  </select>
</div>
<div class="directions">
  To change the end point of the tween, click Pause and drag the nurse to a new location.
</div>
<div class="directions">
  To change the starting point of the tween, use the "Change from direction" select menu.
</div>
<div class="directions">
  There's a hard-coded repeat(-1).repeatDelay(2) but those could be added as menu's too.
</div>
<div id="stage-container" width="800" height="400" style="width: 800px; height: 400px;">
  
  <div id="stage" width="800" height="400" style="width: 800px; height: 400px;">
    
    <svg id="stage-svg-0" class="stage-svg" x="0" y="0" height="400" width="800">
      
      <g id="gp-0" class="svg-wrapper" ref="0" x="50" y="50" height="170" width="170">

        <svg id="svg-0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 170 170" class="svg inline" height="170" width="170">
          <path fill="#FFF" d="M85 170c-46.87 0-85-38.13-85-85S38.13 0 85 0s85 38.13 85 85-38.13 85-85 85z"/>
          <path fill="none" stroke="#282D33" stroke-width="4" d="M93.312 108.145h16.16c6.685 0 12.103 4.796 12.103 10.714v13.39M44.242 132.25v-13.392c0-5.918 5.42-10.714 12.105-10.714h16.13M93.078 100.51v8.206l-10.17 10.872-10.17-10.872v-8.205M57.29 48.265c-2.11 3.162-3.614 6.763-4.343 10.633-4.207 2.49-7.025 6.986-7.025 12.135 0 4.558 2.22 8.592 5.64 11.19-.616 1.323-.966 2.76-.966 4.27 0 6.453 6.197 11.685 13.842 11.685.636 0 1.262-.036 1.874-.106M102.96 91.47c1.166.61 2.493.955 3.9.955 4.667 0 8.45-3.783 8.45-8.45 0-1.903-.186-3.308-1.25-4.722 3.64-2.578 5.564-7.092 5.564-11.815 0-6.16-4.027-11.388-9.648-13.355.106-.376-.496-3.37-2.087-6.02"/>
          <path fill="none" stroke="#282D33" stroke-width="4" d="M105.16 66.653c.84-.307 1.744-.475 2.69-.475 4.318 0 7.82 3.502 7.82 7.82s-3.502 7.82-7.82 7.82M57.156 81.818c-4.318 0-7.818-3.5-7.818-7.82s3.5-7.82 7.818-7.82"/>
          <path fill="none" stroke="#282D33" stroke-width="4" d="M106.976 65.69v11.892c0 14.166-11.483 25.65-25.65 25.65-14.164 0-25.648-11.484-25.648-25.65v-11.89M74.617 91.853c5.156 2.08 10.72 1.608 15.283-.818"/>
          <path fill="none" stroke="#282D33" stroke-width="4" d="M72.52 49.55c-2.196 6.24-6.645 11.74-12.937 15.01-1.686.877-2.967 1.484-4.922 2.158M107.176 66.313c-11.058.62-24.47-2.95-29.73-14.33l-1.27-2.75M73.752 72.673h-4.675M92.492 72.673h-4.674M84.75 82.952h-5.033V70.01"/>
          <path fill="none" stroke="#282D33" stroke-width="4" d="M107.48 49.55h-50v-12.5c15.772-7.726 34.23-7.726 50 0v12.5z"/>
          <g fill="none" stroke="#282D33" stroke-width="4">
            <path d="M82.482 35.48v10.433M87.7 40.696H77.265"/>
          </g>
          <g fill="none" stroke="#282D33" stroke-width="4">
            <path d="M78.375 132.3l-7.225-23.54h-3.877l-4.11 7.146 5.507 4.905-4.188 4.35 3.427 7.14M87.35 132.3l7.224-23.54h3.877l4.113 7.146-5.508 4.905 4.187 4.35-3.427 7.14"/>
          </g>
          <rect width="100%" height="100%" fill="rgba(255,255,255,0"/>
        </svg>
      </g>
    </svg>
  </div>
</div>
              
            
!

CSS

              
                html, body
  font-family: sans-serif

.buttons-wrapper, .menus, .directions
  display: block
  width: 800px
  margin: 0 auto
  overflow: auto
  button
    cursor: pointer
    display: block
    background: blue
    color: white
    border: 0
    padding: 10px 20px
    border-radius: 4px
    font-size: 18px
    margin: 5px
    float: left
  &.menus
    padding-bottom: 5px
  &.directions
    padding: 5px
svg.stage-svg
  position: absolute
  left: 0
  top: 0

.data
  width: 800px
  margin: 5px auto

#stage-container
  position: relative
  width: 800px
  height: 400px
  margin: 0 auto 15px
  background: #000
  border: 4px #6bc28c solid

.buttons
  width: 800px
  position: relative
  display: block
  margin: 10px auto

#stage
  display: block
  width: 800px
  height: 400px
  position: relative
  background: transparent
  position: relative

              
            
!

JS

              
                var tw, svg = $('#gp-0'), stageWd = 800, stageHt = 400, tl = new TimelineMax({ paused: true });

Draggable.create(
  svg, {
    onRelease: function() {
      svg.data("coords", {x: this.endX, y: this.endY, transformOrigin: "center, center"});
      var XY = resetTween();
      addTween(XY);
      play();
    } 
});

function addTween(xyObj) {
  // first get the start and tween time select menu val's
  var duration = parseFloat($('select[name=set-tween]').val());
  var startTime = parseFloat($('select[name=set-start]').val());

  // get the svg's stored x,y values from either the initial placement or Draggable.onRelease
  var toX = svg.data("coords").x;
  var toY = svg.data("coords").y;
  
  // set up the new fromTo tween with above vars
  tw = TweenMax.fromTo(svg, duration, { x: xyObj.x, y: xyObj.y }, {x: toX, y: toY});
  tw.startTime(startTime).repeat(-1).repeatDelay(2);
  tl.add(tw);
}

function resetTween(fromVars) {
  
  var XY;
  if( fromVars === undefined ) {
    XY = tw.vars.startAt;
  } else {
    XY = fromVars;
  }
  
  tl.seek(0);
  tw.invalidate().kill();
  TweenLite.set(svg,{clearProps:"x,y"});
  return(XY);
}

function play() {
  tl.seek(0).play();
  // console.log(tw.vars);
}

function changeStartTime(val) {
  tw.startTime(val);
  tl.pause();
}

function changeTweenDuration(val) {
  tw.duration(val);
}

function init() {
  TweenMax.set(svg, {x: 315, y: 115});
  svg.data("coords", {x: 315, y: 115});
  addTween(inTop());
  play();
}

init();



/*******************************************************************| */
/* THESE ARE JUST LISTENERS FOR BUTTONS AND SELECT MENUS            | */
/*******************************************************************| */
$('.play').on("click", function(){
  play();
});

$('.pause').on("click", function(){
  tl.pause();
});

$('#change-direction').on("change", function(){
  var functionString = $(this).val();
  var xyFrom = eval(functionString)();
  addTween(resetTween(xyFrom));
});

$('#set-tween').on("change", function(){
  changeTweenDuration(parseFloat($(this).val()));
  play();
});

$('#set-start').on("change", function(){
  changeStartTime(parseFloat($(this).val()));
  play();
});

/*******************************************************************| */
/* THESE ARE JUST BEING USED TO CALCULATE NEW FROM POSITIONS        | */
/*******************************************************************| */
function inTop() {
  var X = (stageWd/2) - (parseInt(svg.attr('width')))/2;
  var Y = 0 - parseInt(svg.attr('height'));
  return {x: X, y: Y};
}

function inTopRight() {
  var X = stageWd + parseInt(svg.attr('width'));
  var Y = 0 - parseInt(svg.attr('height'));
  return {x: X, y: Y};
}

function inRight() {
  var X = stageWd + parseInt(svg.attr('width'));
  var Y = (stageHt/2) - (parseInt(svg.attr('height'))/2);
  return {x: X, y: Y};
}

function inBottomRight() {
  var X = stageWd + parseInt(svg.attr('width'));
  var Y = stageHt + parseInt(svg.attr('height'));
  return {x: X, y: Y};
}

function inBottom() {
  var X = (stageWd/2) - (parseInt(svg.attr('width')))/2;
  var Y = stageHt + parseInt(svg.attr('height'));
  return {x: X, y: Y};
}

function inBottomLeft() {
  var X = 0 - parseInt(svg.attr('width'));
  var Y = stageHt + parseInt(svg.attr('height'));
  return {x: X, y: Y};
}

function inLeft() {
  var X = 0 - parseInt(svg.attr('width'));
  var Y = (stageHt/2) - (parseInt(svg.attr('height'))/2);
  return {x: X, y: Y};
}

function inTopLeft() {
  var X = 0 - parseInt(svg.attr('width'));
  var Y = 0 - parseInt(svg.attr('height'));
  return {x: X, y: Y};
}

              
            
!
999px

Console