mirror of
https://github.com/milk-net/milk-net.github.io.git
synced 2025-04-19 05:33:40 -05:00
Create index.html
This commit is contained in:
parent
7546557d69
commit
20438943f7
1 changed files with 166 additions and 0 deletions
166
calculator/index.html
Normal file
166
calculator/index.html
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>MilkNet | Calculator</title>
|
||||||
|
<link rel="icon" type="image/png" href="/assets/img/milk.png"/>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Arial', sans-serif;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
background-color: #000; /* Dark background */
|
||||||
|
color: white; /* White text */
|
||||||
|
}
|
||||||
|
.calculator {
|
||||||
|
background-color: #000; /* Dark calculator background */
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 15px;
|
||||||
|
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
|
||||||
|
width: 280px;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
height: 50px;
|
||||||
|
font-size: 24px;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
background-color: #000;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.buttons {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, 1fr);
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
padding: 20px;
|
||||||
|
font-size: 18px;
|
||||||
|
border: none;
|
||||||
|
background-color: #444; /* Dark buttons */
|
||||||
|
color: white;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s, transform 0.1s;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #555;
|
||||||
|
}
|
||||||
|
button:active {
|
||||||
|
background-color: #666;
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
button:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.button-clear {
|
||||||
|
background-color: #e63946;
|
||||||
|
}
|
||||||
|
.button-equal {
|
||||||
|
background-color: #2a9d8f;
|
||||||
|
grid-column: span 4;
|
||||||
|
}
|
||||||
|
.button-function {
|
||||||
|
background-color: #f1faee;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="calculator">
|
||||||
|
<input type="text" id="display" disabled>
|
||||||
|
<div class="buttons">
|
||||||
|
<button class="button-clear" onclick="clearDisplay()">C</button>
|
||||||
|
<button onclick="deleteLast()">←</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('%')">%</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('/')">/</button>
|
||||||
|
|
||||||
|
<button onclick="appendToDisplay('7')">7</button>
|
||||||
|
<button onclick="appendToDisplay('8')">8</button>
|
||||||
|
<button onclick="appendToDisplay('9')">9</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('*')">*</button>
|
||||||
|
|
||||||
|
<button onclick="appendToDisplay('4')">4</button>
|
||||||
|
<button onclick="appendToDisplay('5')">5</button>
|
||||||
|
<button onclick="appendToDisplay('6')">6</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('-')">-</button>
|
||||||
|
|
||||||
|
<button onclick="appendToDisplay('1')">1</button>
|
||||||
|
<button onclick="appendToDisplay('2')">2</button>
|
||||||
|
<button onclick="appendToDisplay('3')">3</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('+')">+</button>
|
||||||
|
|
||||||
|
<button onclick="appendToDisplay('0')">0</button>
|
||||||
|
<button onclick="appendToDisplay('.')">.</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('**')">^</button>
|
||||||
|
|
||||||
|
<button class="button-function" onclick="appendToDisplay('sin(')">sin</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('cos(')">cos</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay('tan(')">tan</button>
|
||||||
|
|
||||||
|
|
||||||
|
<button class="button-function" onclick="appendToDisplay('(')">(</button>
|
||||||
|
<button class="button-function" onclick="appendToDisplay(')')">)</button>
|
||||||
|
|
||||||
|
|
||||||
|
<button class="button-equal" onclick="calculate()">=</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function clearDisplay() {
|
||||||
|
document.getElementById('display').value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteLast() {
|
||||||
|
let display = document.getElementById('display');
|
||||||
|
display.value = display.value.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendToDisplay(value) {
|
||||||
|
let display = document.getElementById('display');
|
||||||
|
display.value += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculate() {
|
||||||
|
let display = document.getElementById('display');
|
||||||
|
try {
|
||||||
|
display.value = eval(display.value.replace(/sin\(/g, 'Math.sin(').replace(/cos\(/g, 'Math.cos(').replace(/tan\(/g, 'Math.tan('));
|
||||||
|
} catch (e) {
|
||||||
|
display.value = 'Error';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener('keydown', function (e) {
|
||||||
|
const validKeys = [
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||||
|
'.', '/', '*', '-', '+', '=', 'Enter', 'Backspace', 'c',
|
||||||
|
'(', ')', '%', '^'
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
if (validKeys.includes(e.key)) {
|
||||||
|
if (e.key === 'Enter' || e.key === '=') {
|
||||||
|
calculate();
|
||||||
|
} else if (e.key === 'Backspace') {
|
||||||
|
deleteLast();
|
||||||
|
} else if (e.key === 'c' || e.key === 'c') {
|
||||||
|
clearDisplay();
|
||||||
|
} else {
|
||||||
|
appendToDisplay(e.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue