Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yitonghe00/1e07d1b4927a459613f0e70fbc897a1c to your computer and use it in GitHub Desktop.
Save yitonghe00/1e07d1b4927a459613f0e70fbc897a1c to your computer and use it in GitHub Desktop.
<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