css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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>
            
          
!
            
              * {
  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;
}

            
          
!
            
              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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console