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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


                <div class="box green"></div>
<div class="box orange"></div>
<div class="box grey"></div>




  x = distance from target
  v = current velocity
  maxA = maximum acceleration
  dt = elapsed time delta for this frame
  return: "instanteneous" acceleration to close distance to 0 as quickly as maxA allows
const calcAccel = (x, v, maxA, dt) => {
	if(dt === 0) return 0;
  // These following lines is where the magic happens!
	const signX = (x < 0)?-1:1;
	const a = signX * (Math.sqrt(Math.abs(1 + (2 * x) / (maxA * dt * dt))) * maxA - (v * signX) / dt - maxA);
	return Math.min(maxA, Math.max(-maxA, a)); // Clamp acceleration to maxA

const createMover = (maxA, maxV) => {
  let v = 0;
  return (x, dt) => {
    const a = calcAccel(x, v, maxA, dt); // Get "instantaneous" acceleration for this time delta
		v = Math.max(-maxV, Math.min(maxV, v + a * dt)); // Convert "instanteneous" acceleration to tiem delta and clamp velocity to maxV
		return v * dt; // Return velocity adjusted to time delta

const moveBox = (box, maxA, maxV) => {
  const mover ='mover') || createMover(maxA, maxV);'mover', mover);
  box.offset({top: 0});
  let t0, dt;
  const animate = time => {
    mover.rafId = window.requestAnimationFrame(animate);
    if(!t0) return t0 = time;
    dt = (time - t0); t0 = time;
    const offset = box.offset();
    const dist = 400 -; += mover(dist, dt); // Get velocity for this time delta
    box.position(box.offset(offset)); // Update position
    if(dist <= 0) window.cancelAnimationFrame(mover.rafId);
  mover.rafId = window.requestAnimationFrame(animate);

$('').on('click', event => moveBox($(event.currentTarget), 0.01, 10));
$('').on('click', event => moveBox($(event.currentTarget), 0.001, 1));
$('.box.grey').on('click', event => moveBox($(event.currentTarget), 0.001, 1));