Skip to content

Instantly share code, notes, and snippets.

@gustavonovaes
Created August 21, 2019 17:58
Show Gist options
  • Save gustavonovaes/3f31cb59dd7b546b0038b64a993dca37 to your computer and use it in GitHub Desktop.
Save gustavonovaes/3f31cb59dd7b546b0038b64a993dca37 to your computer and use it in GitHub Desktop.
Flex vertical panels with transition
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"
content="ie=edge">
<title>Document</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Neucha&display=swap');
* {
margin: 0;
padding: 0;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
html,
body {
height: 100vh;
}
body {
font-size: 25px;
font-family: 'Neucha', cursive;
}
.panels {
min-height: 100%;
overflow: hidden;
display: flex;
}
.panel {
display: flex;
flex: 1;
flex-direction: column;
align-items: center;
justify-content: center;
box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.1);
background-size: cover;
background-position: center;
padding: 0 20px;
cursor: pointer;
transition:
font-size 0.7s cubic-bezier(0.6, -0.28, 0.735, 0.045),
flex 0.7s cubic-bezier(0.6, -0.28, 0.735, 0.045);
}
.panel:nth-child(1) {
background-image: url('https://images.unsplash.com/photo-1565378435217-e4a764b19d0d?auto=format&q=60&fit=crop&w=500')
}
.panel:nth-child(2) {
background-image: url('https://images.unsplash.com/photo-1497290756760-23ac55edf36f?auto=format&q=60&fit=crop&w=500')
}
.panel:nth-child(3) {
background-image: url('https://images.unsplash.com/photo-1563216368-5b6a40648062?auto=format&q=60&fit=crop&w=500')
}
.panel:nth-child(4) {
background-image: url('https://images.unsplash.com/photo-1563427777882-8c6e10fa4920?auto=format&q=60&fit=crop&w=500')
}
.panel:nth-child(5) {
background-image: url('https://images.unsplash.com/photo-1563863016472-d41d0fbe1056?auto=format&q=60&fit=crop&w=500')
}
.panel>* {
width: 100%;
display: flex;
flex: 1;
align-items: center;
justify-content: center;
transition: transform 0.5s;
}
.panel>*:first-child {
transform: translateY(-100%);
}
.panel.active > *:first-child {
transform: translateY(0)
}
.panel>*:last-child {
transform: translateY(100%);
}
.panel.active > *:last-child {
transform: translateY(0)
}
.panel p {
text-transform: uppercase;
color: white;
text-align: center;
text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
}
/** Trasitions **/
.panel.open {
flex: 5;
font-size: 3em;
}
</style>
</head>
<body>
<main class="panels">
<section class="panel">
<p>UP</p>
<p>Lorem, ipsum dolor sit amet?</p>
<p>DOWN</p>
</section>
<section class="panel">
<p>UP</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>DOWN</p>
</section>
<section class="panel">
<p>UP</p>
<p>Lorem ipsum dolor sit amet .</p>
<p>DOWN</p>
</section>
<section class="panel">
<p>UP</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>DOWN</p>
</section>
<section class="panel">
<p>UP</p>
<p>Lorem ipsum dolor sit.</p>
<p>DOWN</p>
</section>
</main>
<script>
function toggleOpen() {
this.classList.toggle('open');
}
function toggleActive(e) {
if (!e.propertyName.includes('flex')) {
return;
}
this.classList.toggle('active');
}
const panels = document.querySelectorAll('.panel');
panels.forEach(panel => panel.addEventListener('click', toggleOpen))
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment