cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="m-flip__container">
    <p>Click the box</p>
    <div class="m-flip__wrapper">
        <div class="m-flip__box small growing js-flip">
        
        </div>
    </div>
</div>

            
          
!
            
              .m-flip__container {
  width: 100%;
  height: auto;
  font-family: 'Open Sans', sans-serif;
  p {
    margin: 50px auto;
    width: 100px;
  }
}

.m-flip__wrapper {
  width: 400px;
  height: 200px;
  display: block;
  margin: 0 auto;
  position: relative;
}

.m-flip__box {
  background-color: lightblue;
  position: absolute;
  &.small {
    width: 50px;
    height: 50px;
    bottom: 0;
  }
  &.big {
    height: 200px;
    width: 200px;
    left: 200px;
  }
}

.growing {
  transform-origin: bottom left;
  &.transition {
    transition: transform 800ms ease;
  }
}
            
          
!
            
              let elem = document.getElementsByClassName('js-flip'); // store the element

  elem[0].addEventListener('click', function(){ // elem[0] to get the first element (for multiple elements use for loop).

    if (this.classList.contains('small')) {
     
      /*  FIRST: Store the initial size and position  */
      let small = this.getBoundingClientRect();

      /*  LAST: Store the size and position like it would be when the the animation is complete  */
      this.classList.add('growing');
      this.classList.remove('small');
      this.classList.add('big');
      let big = this.getBoundingClientRect();
      this.classList.remove('big');
      this.classList.add('small');
      this.classList.add('transition');

      /*  INVERT: Calculate differences and store them in variables  */
      let invertedLeft = big.left - small.left;
      let invertedWidth = big.width / small.width;
      let invertedHeight = big.height / small.height;

      /*  PLAY: Add transform and release the animation  */
      this.style.transform = 'translateX(' + invertedLeft + 'px) translateZ(0) scale(' + invertedWidth + ', ' + invertedHeight + ')';

      this.addEventListener('transitionend', function handler() {
        this.classList.remove('transition');
        this.style.transform = '';
        this.classList.remove('growing');
        this.classList.remove('small');
        this.classList.add('big');
        this.removeEventListener('transitionend', handler);
      });

    } else {
      this.classList.add('small');
      this.classList.remove('big');
    }

  });
            
          
!
999px
Loading ..................

Console