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

              
                <button id='start' onclick='start()'>Start Easing</button>
<button id='reset' onclick='reset()'>Reset</button>
<input type='checkbox' id='showPath' checked/>
<label for='showPath'>Show Path</label>
<div>
  <input type="radio" id="linear" name="easing" value="linear"
         checked>
  <label for="linear">Linear</label>
</div>
<div>
  <input type="radio" id="easeIn" name="easing" value="easeIn">
  <label for="easeIn">Ease In</label>
</div>
<div>
  <input type="radio" id="easeOut" name="easing" value="easeOut">
  <label for="easeOut">Ease Out</label>
</div>
<div>
  <input type="radio" id="easeInOut" name="easing" value="easeInOut">
  <label for="easeInOut">Ease In Out</label>
</div>
<svg viewBox='0 0 500 100' height='150' id='linear-fn'>
  <g id='lf-circles'></g>
  <g id='lf-circleProg'></g>
</svg>
<svg viewBox='0 0 500 100' height='150' id='choose-fn'>
  <g id='cf-circles'></g>
  <g id='cf-circleProg'></g>
</svg>

              
            
!

CSS

              
                .move-linear{
  transform: translateX(400px) ;
  transition: 4s linear;
  fill: pink;
}

/* https://matthewlein.com/tools/ceaser */
.move-easeIn {
  transform: translateX(400px);
  transition: 4s ease-in;
  fill: pink;
}

.move-easeOut {
  transform: translateX(400px);
  transition: 4s ease-out;
  fill: pink;
}

.move-easeInOut {
  transform: translateX(400px);
  transition: 4s ease-in-out;
  fill: pink;
}
              
            
!

JS

              
                var rad = document.getElementsByName("easing");
const easingFns = {
  linear: (t) => t,
  easeIn: (t) => BezierEasing(0.42, 0.0, 1.00, 1.0)(t),
  easeOut: (t) => BezierEasing(0.00, 0.0, 0.58, 1.0)(t),
  easeInOut: (t) => BezierEasing(0.42, 0.0, 0.58, 1.0)(t),
};
let easingFn = 'linear';
for (var i = 0; i < rad.length; i++) {
  rad[i].addEventListener("change", function() {
    reset();
    easingFn = this.value;
  });
}


var showPathEl = document.getElementById('showPath');
var showPath = showPathEl.checked;
showPathEl.addEventListener('change', function(event) {
  showPath = event.target.checked;
})

const x1 = 50;
const x2 = 450;
const duration = 40;
const totalTime = 100 * duration;

const easingEq = (duration, fn) => {
  const arr = [];
  let curr = 0;
  for (i = 1; i <= duration; i++) {
    curr = easingFns[fn](i/duration);
    arr.push(curr);
  }
  return arr;
};

const drawDelay = (i, time, circleSet, circleProg) => {
  setTimeout(() => {
       circleProg.innerHTML = circleProg.innerHTML + circleSet[i];
  }, time);
};

const startEasing = (fn, circleProg) => {
  const points = easingEq(duration, fn);
  const gap = x2 - x1;
  const circleSet = points.map(
    p =>
      `<rect x='${x1 +
        gap * p}' y='50' width='10' height='20' fill='pink' stroke='black' opacity='0.6'/>`
  );
  let i = 0;
  while (i < duration) {
    const time = totalTime * points[i];
    drawDelay(i, time, circleSet, circleProg);
    i = i + 1;
  }
};

const start = () => {
  reset();
  if(showPath){
    startEasing("linear", document.getElementById("lf-circleProg"));
    startEasing(easingFn, document.getElementById("cf-circleProg"));
  } else {
    document.getElementById('lf-start').classList.add(`move-linear`);
    document.getElementById('cf-start').classList.add(`move-${easingFn}`);
  }
};

const reset = () => {
  document.getElementById("cf-circleProg").innerHTML = "";
  document.getElementById("lf-circleProg").innerHTML = "";
  document.getElementById('lf-start').classList.remove(`move-linear`);
  document.getElementById('cf-start').classList.remove(`move-${easingFn}`);
};

const createInitCircles = (cx1, cx2, id) => {
  return `<rect x='${cx1}' y='50' height='20' width='10' fill='none' stroke='black' id='${id}-start'/> <rect x='${cx2}' y='50' height='20' width='10' fill='none' stroke='black' stroke-dasharray="1,1" id='${id}-end'/>  `;
};

const init = () => {
  document.getElementById("lf-circles").innerHTML = createInitCircles(x1, x2, 'lf');
  document.getElementById("cf-circles").innerHTML = createInitCircles(x1, x2, 'cf');
};

init();

              
            
!
999px

Console