Created
May 17, 2022 04:58
-
-
Save yitonghe00/1e07d1b4927a459613f0e70fbc897a1c to your computer and use it in GitHub Desktop.
This file contains 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
<p style="font-size: 16px;">🎈</p> | |
<script> | |
const p = document.querySelector('p'); | |
const inflate = (event) => { | |
event.preventDefault(); | |
const size = Number(p.style.fontSize.slice(0, -2)); | |
if (size > 100) { | |
p.textContent = '💥'; | |
window.removeEventListener('keydown', keydownHandler); | |
} | |
p.style.fontSize = `${size + 10}px` | |
}; | |
const deflate = (event) => { | |
event.preventDefault(); | |
const size = Number(p.style.fontSize.slice(0, -2)); | |
if (size <= 10) { | |
return; | |
} | |
p.style.fontSize = `${size - 10}px` | |
}; | |
const keydownHandler = (event) => { | |
if (event.key === "ArrowUp") { | |
inflate(event); | |
} else if (event.key === "ArrowDown") { | |
deflate(event); | |
} | |
}; | |
window.addEventListener("keydown", keydownHandler); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment