Created
December 23, 2025 02:56
-
-
Save greggman/2df7759c5c19ab61895d86e72e17cbcf to your computer and use it in GitHub Desktop.
Image Comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .comparison-slider { | |
| position: relative; | |
| width: 100%; /* Fully responsive */ | |
| } | |
| .comparison-slider img { | |
| width: 100%; | |
| display: block; /* Removes bottom gap */ | |
| } | |
| .image-overlay { | |
| position: absolute; | |
| inset: 0 auto 0 0; /* top, right, bottom, left shorthand */ | |
| width: 50%; | |
| overflow: hidden; | |
| } | |
| /* THE FIX: Prevents top image from shrinking or sliding */ | |
| .image-overlay img { | |
| width: 100%; | |
| height: 100%; | |
| object-fit: cover; | |
| object-position: left; | |
| } | |
| .slider { | |
| position: absolute; | |
| inset: 0; | |
| width: 100%; | |
| appearance: none; | |
| background: transparent; | |
| cursor: ew-resize; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="comparison-slider"> | |
| <img src="https://webgpufundamentals.org/webgpu/resources/images/lut/bgy-s8.png" alt="After image" class="image-after"> | |
| <div class="image-overlay"> | |
| <img src="https://webgpufundamentals.org/webgpu/resources/images/lut/black-white-s8n.png" alt="Before image"> | |
| </div> | |
| <input type="range" min="0" max="100" value="50" class="slider"> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const slider = document.querySelector('.slider'); | |
| const overlay = document.querySelector('.image-overlay'); | |
| slider.addEventListener('input', (e) => { | |
| const sliderValue = e.target.value; | |
| overlay.style.width = `${sliderValue}%`; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"name":"Image Comparison","settings":{},"filenames":["index.html","index.css","index.js"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment