Created
November 24, 2025 23:20
-
-
Save plugn/3a1b1e1275441d0603e4278a3b3bf4bb to your computer and use it in GitHub Desktop.
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
| body { | |
| min-height: 100vh; | |
| margin: 0; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| } | |
| div { | |
| width: 105px; | |
| height: 105px; | |
| background: #ccddff; | |
| padding: 5px; | |
| } |
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 id="scaling-box">Scale me with your mouse wheel.</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
| /** | |
| * https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event#examples | |
| */ | |
| let scale = 1 | |
| const el = document.querySelector('#scaling-box') | |
| function applyZoom(event) { | |
| event.preventDefault() | |
| scale += event.deltaY * -0.01 | |
| // Restrict scale | |
| scale = Math.min(Math.max(0.125, scale), 4) | |
| // Apply scale transform | |
| el.style.transform = `scale(${scale})` | |
| } | |
| el.onwheel = applyZoom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment