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. 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

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="controls">
 <label for="stage-resize">Set stage size: </label>
  <select name="stage-resize" id="stage-resize">
    <option value="1280">1280x720</option>
    <option value="1024">1024x576</option>
    <option value="800">800x450</option>
  </select> 
  <button id="restart">Restart</button>
  <button id="pause">Pause</button>
</div>
<div id="container">
  <svg viewBox="0 0 800 450">
    <path class="path"/>
  </svg>
  <div class="box"></div>
</div>

              
            
!

CSS

              
                body
  background: black
  color: white
  font-family: 'helvetica neue', helvetica, arial, sans-serif
.controls, svg
  position: relative
  display: block
  margin-top: 10px
svg

  max-width: 100%
  height: 100%
  width: 100%
path
  stroke: red
  stroke-width: 1
  fill: none
.box
  display:block
  position: absolute
  height: 50px
  width: 50px
  background: red
  top: 0
  left: 0
#container
  display: block
  position: relative
  background: #aaaaaa
  
              
            
!

JS

              
                let p = "M0 0 l800 79-800 59 800 66-800 62 800 71-800 77 400 51",
  stage = document.querySelector("#container"),
  svg = document.querySelector("svg"),
  path = document.querySelector(".path");

var bPath = MorphSVGPlugin.pathDataToBezier(p);
var defaultSize = {wd: 800, ht: 450};
var resizeObj =  {wd: 1280, ht: 720};

resizeStage(resizeObj);

function fillStage(obj) {
  // change path points to fill stage
}

function resizeStage(obj) {
  TweenMax.set("#container", { width: obj.wd, height: obj.ht });
  // fillStage(obj);
  resizeObj = obj;
  if(tween){
    tween.invalidate();
  }
  
}

$("select#stage-resize").on("change", function() {
  switch ($(this).val()) {
    case "1280":
      resizeStage({ wd: 1280, ht: 720 });
      break;
    case "1024":
      resizeStage({ wd: 1024, ht: 576 });
      break;
    case "800":
      resizeStage({ wd: 800, ht: 450 }); 
      break;
  }
});

restart.addEventListener('click', function(){
  TweenMax.set('.box', {x: 0, y: 0});
  tween.invalidate();
  tween.restart();
})

pause.addEventListener('click', function(){
  tween.pause();
})

path.setAttributeNS(null, "d", p);

var tween = TweenMax.to(".box", 10, {
  bezier: { values: bPath, type: "soft" },
  modifiers: {
    x: function(value) {
      return value * (resizeObj.wd / defaultSize.wd);
    },
    y: function(value) {      
      return value * (resizeObj.ht / defaultSize.ht);
    }
  }
}); 
              
            
!
999px

Console