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.

              <div id="wrap">
  <div class="description" id="step1"><strong>Step 1:</strong> use <code>getBBox()</code> to calculate the x/y offsets from the SVG's 0,0 coordinates to the desired transform origin. In this case, it's x:300, y:100 (white dot).</div>
<div class="description" id="step2"><strong>Step 2:</strong> to normalize behavior among browsers, set <code>transform-origin: 0px 0px</code> (blue dot)</div>
<div class="description" id="step3"><strong>Step 3:</strong> on each tick of the animation, update the transform value (in this case, rotation). Notice the center has drifted from the desired origin.</div>
<div class="description" id="step4"><strong>Step 4:</strong> adjust the position of the rectangle (using x and y portions of the transform matrix) to align with the desired origin (white dot). This is all seamless during the animation.</div>

<svg version="1.1" id="container" class="container" width="550" height="300"  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 550 300" xml:space="preserve">
  <g id="rectWithOffset">
  <rect id="rect" class="animated-rectangle" x="100" y="50" width="400" height="100" fill="#91e600" />
  <line id="offset" x1="0" y1="0" x2="300" y2="100" stroke="#cc00cc" stroke-width="10" stroke-dasharray="317" stroke-linecap="round" stroke-linejoin="round" stroke-dashoffset="317" />
  <circle id="realOrigin" cx="300" cy="100" r="12" fill="#0077FF" style="visibility:hidden" />
  <circle id="origin" cx="300" cy="100" r="12" fill="#FFFFFF" />
  <text y="280" x="275" width="550" id="originText" text-anchor="middle">Desired transform-origin: 50% 50%</text>

<button id="next" class="dark-grey-button club-demo-button">next</button>

              body {
  background-color: black;
  margin: 0;
  padding: 0;
  color: #ccc;
  font-family: Arial, sans-serif;
  font-size: 20px;
  text-align: center;
#wrap {
  width: 555px;
  height: 420px;
  padding: 12px 0 0 12px;
  overflow: hidden;
  text-align: left;
  display: inline-block;
#originText {
  color: white;
  fill: white;
  font-family: monospace;
.description {
  width: 550px;
  position: absolute;

#container {
  overflow: hidden;
  border: 2px solid #555;
  margin-top: 16px;
  position: relative;
  top: 100px;
code, strong {
  color: white;
#next {
  position: absolute;
  top: 87px;
  left: 502px;

              var master = new TimelineMax();
master.add(step1(), "step1")
  .addLabel("step2", "-=1")
  .addPause("step2", inviteNext)
  .add(step2(), "step2+=0.3")
  .addLabel("step3", "-=1")
  .addPause("step3", inviteNext)
  .add(step3(), "step3+=0.3")
  .addLabel("step4", "-=1")
  .addPause("step4", inviteNext)
  .add(step4(), "step4+=0.3");

var flashingNext = new TimelineMax({repeat:-1, repeatDelay:5, paused:true});
flashingNext.to("#next", 0.12, {opacity:0, repeat:5, yoyo:true});
function inviteNext() {

$("#next").click(function() {
  if (master.progress() === 1) {
  } else if (!master.paused()) {
    master.play( master.getLabelAfter( master.time() ) + "+=0.001" ); //add a little time, otherwise it'll run into the addPause() and pause right away.
  } else {

function step1() {
  var tl = new TimelineLite();
  tl.from("#step1", 0.5, {autoAlpha:0})
    .to("#offset", 1.5, {attr:{"stroke-dashoffset":0}, ease:Linear.easeNone})
    .from("#origin", 0.5, {attr:{r:0}})
    .to("#step1", 0.7, {autoAlpha:0, x:-100}, "+=2.5");
  return tl;
function step2() {
  var tl = new TimelineLite();
  tl.from("#step2", 0.7, {autoAlpha:0, x:100})
    .to("#realOrigin", 2, {attr:{cx:0, cy:0}, visibility:"visible", ease:Power1.easeInOut})
    .to("#step2", 0.7, {autoAlpha:0, x:-100}, "+=2");
  return tl;
function step3() {
  var tl = new TimelineLite();
  tl.from("#step3", 0.7, {autoAlpha:0, x:100})
    .to("#rectWithOffset", 2.5, {rotation:20, transformOrigin:"-100px -50px", force3D:true, ease:Power1.easeInOut}, "rotate")
    .to("#offset", 2.5, {rotation:20, force3D:true, ease:Power1.easeInOut}, "rotate")
    .to("#step3", 0.7, {autoAlpha:0, x:-100}, "+=3");
  return tl;
function step4() {
  var tl = new TimelineLite();
  tl.from("#step4", 0.7, {autoAlpha:0, x:100})
    .to("#rectWithOffset", 1.5, {x:52.294, y: -96.575, ease:Power1.easeInOut})
    .to("#next", 0.5, {text:"restart", x:-26})
    .to("#offset, #realOrigin", 0.5, {opacity:0}, "+=1")  
    .to("#rect", 2, {rotation:340, transformOrigin:"50% 50%", ease:Power1.easeInOut}, "-=0.5");
  return tl;
🕑 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.