Skip to content

Instantly share code, notes, and snippets.

@thehale
Created May 11, 2026 20:00
Show Gist options
  • Select an option

  • Save thehale/73a29e070a1b81432c0fdb82cee301c3 to your computer and use it in GitHub Desktop.

Select an option

Save thehale/73a29e070a1b81432c0fdb82cee301c3 to your computer and use it in GitHub Desktop.
Slide Fade Navigation Demo
screenrecording-2026-05-11_12-59-33.mp4
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Slide/Fade Pane Demo</title>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: #ddd;
font-family: system-ui, sans-serif;
}
.backdrop {
width: min(700px, calc(100vw - 32px));
padding: 24px;
background: white;
border: 1px solid #aaa;
}
.controls {
display: flex;
gap: 8px;
margin-bottom: 12px;
}
button {
padding: 8px 12px;
font: inherit;
cursor: pointer;
}
button:disabled {
cursor: default;
opacity: 0.5;
}
.switcher {
display: grid;
overflow: hidden;
min-height: 220px;
border: 1px solid #333;
background: #f7f7f7;
}
.pane {
grid-area: 1 / 1;
display: grid;
place-items: center;
min-height: 220px;
font-size: 48px;
opacity: 0;
pointer-events: none;
visibility: hidden;
transition:
opacity 200ms ease,
transform 250ms ease,
visibility 0s linear 250ms;
}
.switcher[data-view="one"] .pane-one,
.switcher[data-view="two"] .pane-two {
opacity: 1;
pointer-events: auto;
visibility: visible;
transform: translateX(0);
transition:
opacity 200ms ease,
transform 250ms ease,
visibility 0s linear 0s;
}
.switcher[data-view="one"] .pane-two {
transform: translateX(100%);
}
.switcher[data-view="two"] .pane-one {
transform: translateX(-100%);
}
.pane-one {
background: #f2efe8;
}
.pane-two {
background: #e8f0f2;
}
</style>
</head>
<body>
<div class="backdrop">
<div class="controls">
<button type="button" data-show="one">Pane 1</button>
<button type="button" data-show="two">Pane 2</button>
</div>
<div class="switcher" data-view="one">
<div class="pane pane-one">pane 1</div>
<div class="pane pane-two">pane 2</div>
</div>
</div>
<script>
const switcher = document.querySelector(".switcher")
const buttons = document.querySelectorAll("[data-show]")
function showPane(nextView) {
switcher.dataset.view = nextView
for (const button of buttons) {
button.disabled = button.dataset.show === nextView
}
}
for (const button of buttons) {
button.addEventListener("click", () => showPane(button.dataset.show))
}
showPane("one")
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment