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="panels">
  <div class="panel panel1">
    <p>I'm</p>
    <p>Hello</p>
    <p>Yoshihiko</p>
  </div>
  <div class="panel panel2">
    <p>Dancing</p>
    <p>Let's</p>
    <p>Together!!</p>
  </div>
  <div class="panel panel3">
    <p>Show</p>
    <p>Thanks</p>
    <p>Me</p>
  </div>
  <div class="panel panel4">
    <p>I am</p>
    <p>Always</p>
    <p>Happy!!</p>
  </div>
  <div class="panel panel5">
    <p>Have a</p>
    <p>Goodbye</p>
    <p>Nice day!!</p>
  </div>
</div>
            
          
!
            
              body {
  margin: 0;
}

.panels {
  min-height:100vh;
  overflow: hidden;
  display: flex;
}

.panel {
  background:#6B0F9C;
  box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1);
  color:white;
  text-align: center;
  align-items:center;
/*   ここのtransitionがopenクラスを付与した時のポイントとなる部分。 */
  transition:
    font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
    flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
    background 0.2s;
  font-size: 20px;
  background-size:cover;
  background-position:center;
  flex: 1;
  justify-content: center;
  display: flex;
  flex-direction: column;
}


.panel1 { background-image:url(https://1.bp.blogspot.com/-aC2jXDBJcuY/VpjBp16ShbI/AAAAAAAA25w/pL6seXQvsM0/s1600/bg_natural_sougen.jpg); }
.panel2 { background-image:url(https://4.bp.blogspot.com/-8eVWfvvNu2E/V9vBHI-5lDI/AAAAAAAA92M/fNk7xdy6kME1_cUEWcXBIkX39vAn3daZwCLcB/s2000/bg_music_live_stage.jpg); }
.panel3 { background-image:url(https://1.bp.blogspot.com/-HDIqW5OPyGw/VtR8keHJi6I/AAAAAAAA4Qc/wU2w_ApPhSk/s1600/bg_sabaku.jpg); }
.panel4 { background-image:url(https://3.bp.blogspot.com/-dO-pdRfLT-E/V8jqV3zqiUI/AAAAAAAA9dI/-ggjHn6j_xM1GeDPqqZS8ThQBr8bZitzQCLcB/s2000/bg_doujou.jpg); }
.panel5 { background-image:url(https://1.bp.blogspot.com/-xkFdFkjkt6E/VpjBqm4-vEI/AAAAAAAA26M/69G2fAaMFy0/s1600/bg_outside_jutaku_yoru.jpg); }

.panel > * {
  margin:0;
  width: 100%;
  transition:transform 0.3s;
  flex: 1 0 auto;
  display:flex;
  justify-content: center;
  align-items: center;
}

/* translateYで1番目と3番目の要素を上下に逃してる。jsでクラスを追加することでtransformで元の位置に。 */
.panel > *:first-child {
  color: #ad3530;
  transform: translateY(-100%); 
}
.panel.open-active > *:first-child { transform: translateY(0); }

.panel > *:last-child {
  color: #ad3530;
  transform: translateY(100%); 
}
.panel.open-active > *:last-child { transform: translateY(0); }

.panel p {
  text-transform: uppercase;
  font-size: 2em;
}
/* 2番目の子要素の文字サイズを指定 */
.panel p:nth-child(2) {
  font-size: 4em;
}
/* openクラスがあたったときの処理で、flexのグリットを拡大させることで他のものより大きく見せることができる。 */
.panel.open {
  flex: 5;
  font-size:40px;
}
            
          
!
            
              const panels = document.querySelectorAll('.panel');

function toggleOpen() {
  this.classList.toggle('open')
}

function toggleActive(e) {
  if (e.propertyName.includes('flex')) {
    this.classList.toggle('open-active');
  }
}

panels.forEach(panel => panel.addEventListener('click', toggleOpen));
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
            
          
!
999px
Loading ..................

Console