Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

HTML

              
                <div class="app">  
  <div class="content">
    <div class="container">
      <div class="element">
        <div class="calendarHead">
        </div>
         <div class="Date">
           <div>10/20 Sat</div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="element collapsed">
        <div class="calendarHead">
        </div>
         <div class="Date">
           10/21 Sun
        </div>
      </div>
    </div>
    <div class="container">
      <div class="element collapsed">
        <div class="calendarHead">
        </div>
         <div class="Date">
           10/22 Mon
        </div>
      </div>
    </div> 
      <div class="container">
        <div class="element collapsed">
          <div class="calendarHead">
          </div>
          <div class="Date">
            10/23 Tue
          </div>
        </div>
      </div>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  background-color: #fdd62f;
  align-items: center;
  height: 100%;
  font-family: 'Roboto', sans-serif;
}

body {
  padding: 20px 0 ;
}

.app {
    width: 375px;
    max-height: 620px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.content {
  flex: 1;
  overflow: hidden;
  position: relative;
  height: 100%;
}

.container {
  height: 155px;
}

.element {
  cursor: pointer;
  height: 155px;
  width: 375px;
}

.calendarHead {
  height: 40px;
  background-color: #03A9F4;
}

.Date {
  background-color: #fbffd9;
  height: 115px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  position: absolute;
  z-index: 0;
  width: 100%;
}

.Date.expanded {
  top: 0;
  left: 0;
  z-index: 1;
  height: 600px;
  position: absolute;
}

.transition {
  transition: 550ms ease-in;
  z-index: 1;
}

              
            
!

JS

              
                const content = document.querySelector('.content');
content.addEventListener('click', function(event) {
  const targetClassName = event.target.className;
  if (targetClassName.indexOf('Date') !== -1) {
    const elem = event.target;
    if (elem.classList.contains('expanded')) {
      // Fisrt: 記錄初始狀態
      const expanded = elem.getBoundingClientRect();
      // 進行運算, 套用動畫結尾的 css style
      elem.classList.remove('expanded');
      
      // Last: 紀錄結束狀態
      const collapsed = elem.getBoundingClientRect();
      
      // INVERT

      // 根據在 F 與 L 紀錄的位置,我們算出其位置差距 (top 與 left)
      const invertedTop = expanded.top - collapsed.top;
      const invertedLeft = expanded.left - collapsed.left;
      // 大小的部分則是用寬高差去計算 scale 的比例
      const invertedWidth = expanded.width / collapsed.width;
      const invertedHeight = expanded.height / collapsed.height;
      
      // 設定 transform origin,代表動畫要從哪裡開始
      elem.style.transformOrigin = 'top left';
      // 將算好的差距 apply 到 transform 屬性上
      // 這樣就能將元件 ”翻“ 回初始位置
      elem.style.transform = 'translate(' + invertedLeft + 'px, ' + invertedTop + 'px) scale(' + invertedWidth + ', ' + invertedHeight + ')'; 
      
      // PLAY
      // 利用 Raf,在下個 frame 開始時再做動畫
      requestAnimationFrame(function(){
        // 設定 transition,並移除 transform,讓他再 "翻" 到結尾位置
        elem.style.transition = '550ms ease-out';
        elem.style.transform = '';
      });
      // 等 transition 動畫完後, 把 style 上的 transition 清空
      elem.addEventListener('transitionend', function() {
        elem.style.transition = '';
      });
    } else {
      // Fisrt: 記錄初始狀態
      const collapsed = elem.getBoundingClientRect();
      
      // 進行運算, 套用動畫結尾的 css style
      elem.classList.add('expanded');
      
      // Last: 紀錄結束狀態
      const expanded = elem.getBoundingClientRect();
      
      // INVERT

      // 根據在 F 與 L 紀錄的位置,我們算出其位置差距 (top 與 left)
      const invertedTop = collapsed.top - expanded.top;
      const invertedLeft = collapsed.left - expanded.left;
      // 大小的部分則是用寬高差去計算 scale 的比例
      const invertedWidth = collapsed.width / expanded.width;
      const invertedHeight = collapsed.height / expanded.height;
      
      // 設定 transform origin,代表動畫要從哪裡開始
      elem.style.transformOrigin = 'top left';
      // 將算好的差距 apply 到 transform 屬性上
      // 這樣就能將元件 ”翻“ 回初始位置
      elem.style.transform = 'translate(' + invertedLeft + 'px, ' + invertedTop + 'px) scale(' + invertedWidth + ', ' + invertedHeight + ')'; 
      
      // PLAY
      // 利用 Raf,在下個 frame 開始時再做動畫
      requestAnimationFrame(function(){
        // 設定 transition,並移除 transform,讓他再 "翻" 到結尾位置
        elem.style.transition = '550ms ease-out';
        elem.style.transform = '';
      });
      elem.addEventListener('transitionend', function() {
        elem.style.transition = '';
      });
    }
  }
});
              
            
!
999px

Console