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

              
                <div class="contrain" id="js-constrain"></div>




















<!-- ABOUT LINK -->
<style> .what:hover { cursor: pointer; opacity: .75; } .what {display: block;width: 28px;height: 28px;position: fixed;right: 20px;bottom: 70px;background-size: 100% 100%; background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB3aWR0aD0iMjNweCIgaGVpZ2h0PSIyM3B4IiB2aWV3Qm94PSIwIDAgMjMgMjMiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+ICAgICAgICA8dGl0bGU+U2xpY2UgMTwvdGl0bGU+ICAgIDxkZXNjPkNyZWF0ZWQgd2l0aCBTa2V0Y2guPC9kZXNjPiAgICA8ZGVmcz48L2RlZnM+ICAgIDxnIGlkPSJQYWdlLTEiIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiB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D0iPyIgZmlsbD0iIzNBMDUzQSI+PC9wYXRoPiAgICA8L2c+PC9zdmc+);}</style><a href="http://mojs.io/tutorials/shape/" class="what" title="tutorial" target="_blank"></a>
<!-- ABOUT LINK -->
              
            
!

CSS

              
                body, html {
  padding: 0;
  margin:  0;
  width: 100%;
  height: 100%;
  // overflow: hidden;
}

body {
  background: rgba(241, 226, 215, 0.2);
  background: #777;
  position: relative;
  background: #EA485C;
}

.contrain {
  overflow:       hidden;
  position:       absolute;
  width:          140px;
  height:         100px;
  left:           50%;
  top:            50%;
  margin-left:    -70px;
  margin-top:     -50px;
  z-index:        1;
  // outline: 1px solid white;
}
              
            
!

JS

              
                const DURATION = 400;
const BOUNCE_DURATION = 400;
const constrain = document.body.querySelector('#js-constrain');
const X_SHIFT = 300;

const rectShadow = new mojs.Shape({
  shape:      'rect',
  fill:       'rgba(0,0,0, .2)',
  parent:     constrain,
  top:        '100%',
  left:       '23%',
  radius:     2,
  radiusX:    20,
  x:          21,
  rx:         3,
  opacity:    { 1 : .25 },
  scaleX:     { 1 : .75 },
  origin:     '0 50%',
  easing:     'cubic.out',
  delay:      200,
  duration:   250,
  // isShowStart: true,
  isShowEnd:    false,
  isForce3d:    true
}).then({
  opacity: { to: 1, easing: 'bounce.out' },
  scaleX: { to: 1, easing: 'bounce.out' },
  duration: BOUNCE_DURATION
});

const {approximate} = mojs.easing;

const easeOutUpper = (p) => {
  return mojs.easing.cubic.out(p) - p;
}

const easeOut = mojs.easing.mix(
  {to: .5, value: .375}, { to: 1, value: easeOutUpper } );

const SQUASH_SIZE = 1.5;

const scaleCurve = approximate((p) => {
   return 1 + SQUASH_SIZE*easeOut(p);
});

const nScaleCurve = approximate((p) => {
   return 1 - SQUASH_SIZE*easeOut(p);
});

const rect = new mojs.Shape({
  parent:   constrain,
  shape:    'rect',
  rx:       3,
  fill:     '#29363B',
  left:     '22%',
  top:      '100%',
  radius:   20,
  y:        -20,
  x:         22,
  scaleX:   { 1: 1, curve: scaleCurve },
  scaleY:   { 1: 1, curve: nScaleCurve },
  origin:   '0 100%',
  duration: 200,
  isForce3d:  true
}).then({
  angle: { to: -45, easing: 'cubic.out' },
  duration: 250,
}).then({
  angle: { to: 0, easing: 'bounce.out' },
  duration: BOUNCE_DURATION
});

const dustOpts = {
  parent:   constrain,
  radius:   20,
  fill:     'white',
  radius:   'rand(3, 15)',
  left:     '20%',
  top:      '100%',
  scale:    { 1: 0 },
  x:        { 0: 70 },
  y:        { 0: -20 },
  isForce3d: true,
  swirlSize: 50,
  swirlFrequency: 1,
  isTimelineLess: true,
}

const dust = new mojs.Timeline;

for (var i = 0; i < 7; i++) {
  dust.add( new mojs.ShapeSwirl({
      ...dustOpts,
      delay:  i*45
    })
  )
}

const dustTrail = new mojs.Timeline;

for (var i = 0; i < 2; i++) {

  let direction = ( i % 2 === 0 ) ? 1 : -1;
  let pathScale = ( i % 2 === 0 ) ? 1 : .75;

  dustTrail.add( new mojs.ShapeSwirl({
      ...dustOpts,
      radius:   'rand(10, 15)',
      delay:  200 + i*45,
      direction,
      pathScale,
      swirlSize: 10,
      swirlFrequency: 3,
    })
  )
}


mojs.h.force3d( constrain );
const constrainTween = new mojs.Tween({
  onUpdate: (p) =>  {
    constrain.style[ 'transform' ] =
      `translateX(${X_SHIFT*(1-p)}px)`;
  },
  duration: DURATION
});

const timeline = new mojs.Timeline({ delay: 500, speed: .5 });

timeline
  .add(
    constrainTween, rect, rectShadow,
    dust, dustTrail
  );

new MojsPlayer({ add: timeline, isPlaying: true, isRepeat: true });
              
            
!
999px

Console