Created
October 17, 2023 00:27
-
-
Save AliAlmasi/d8eee90a69bc94f60dd647563dc4a0f7 to your computer and use it in GitHub Desktop.
Simple counter w/ JS
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Counter.Js</title> | |
<style> | |
*, | |
*::before, | |
*::after { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
user-select: none; | |
} | |
html { | |
font-size: 62.5%; | |
font-family: monospace | |
} | |
body { | |
display: flex; | |
height: 100vh; | |
width: 100vw; | |
justify-content: center; | |
align-items: center; | |
font-size: medium; | |
background: linear-gradient(112.1deg, #202639 11.4%, #3f4c77 70.2%); | |
color: #1b1f2c; | |
} | |
main { | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
gap: 1.6rem; | |
padding: 4rem 6rem; | |
background-color: #ffffff66; | |
border-radius: 16px; | |
box-shadow: 0 4px 25px #00000033; | |
border: 1px solid #d7d9e0; | |
} | |
h1 { | |
letter-spacing: 3px; | |
font-weight: 900; | |
} | |
#counterbox { | |
display: flex; | |
justify-content: space-between; | |
align-items: center; | |
gap: 2rem; | |
} | |
#number { | |
font-size: 3rem; | |
background-color: #2b334b; | |
border: 3px solid #d7d9e0; | |
color: #d7d9e0; | |
padding: 1rem 3rem; | |
font-weight: 500; | |
border-radius: 100000px; | |
text-align: center; | |
user-select: text; | |
transition: background-color .2s; | |
} | |
#number:hover { | |
background-color: #202639; | |
} | |
.buttons { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
border: 2px solid #d7d9e0; | |
border-radius: 100000px; | |
width: 5rem; | |
height: 5rem; | |
transition: background-color .2s; | |
font-size: 5rem; | |
} | |
.buttons:hover { | |
cursor: pointer; | |
background-color: #ffffff33; | |
} | |
</style> | |
</head> | |
<body> | |
<main> | |
<h1>Counter.Js</h1> | |
<div id="counterbox"> | |
<span id="minus" class="buttons">-</span> | |
<span id="number"></span> | |
<span id="plus" class="buttons">+</span> | |
</div> | |
</main> | |
<script defer> | |
let counter_number = 0; | |
const plus_button = document.querySelector(`#plus`); | |
const minus_button = document.querySelector(`#minus`); | |
const number = document.getElementById("number"); | |
number.textContent = counter_number; | |
plus_button.addEventListener('click', () => { | |
counter_number++; | |
number.textContent = counter_number; | |
}) | |
minus_button.addEventListener('click', () => { | |
counter_number--; | |
number.textContent = counter_number; | |
}) | |
</script> | |
</body> | |
</html> |
b4r3l9a1i7e
commented
Mar 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment