-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.html
170 lines (157 loc) · 4 KB
/
calculator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Calculator</title>
</head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Courier New", Courier, monospace;
user-select: none;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #00c3ff;
}
.calculator {
position: relative;
width: 300px;
}
.calculator .buttons {
position: relative;
display: grid;
}
.calculator .buttons #value {
position: relative;
width: 293px;
left: 2px;
grid-column: span 4;
height: 100px;
line-height: 100px;
padding: 0 20px;
border-radius: 10px;
background: #fa6bff;
text-align: right;
font-size: 1.5rem;
color: #000;
overflow: hidden;
box-shadow: inset 0 6px 1px 0 rgba(0, 0, 0, 0.35),
0 5px 5px rgba(0, 0, 0, 0.5), 0 5px 25px rgba(0, 0, 0, 0.35);
margin-bottom: 12px;
pointer-events: none;
}
.calculator .buttons #value::before {
content: "";
position: absolute;
inset: 5px 3px;
border-top: 4px solid #ccc;
filter: blur(2px);
}
.calculator .buttons span {
position: relative;
padding: 10px;
padding-top: 15px;
margin: 2px;
margin-top: 10px;
min-width: 40px;
font-size: 22px;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
border: 1px solid #222;
border-radius: 6px;
background: linear-gradient(#ff9900, #ffd900);
box-shadow: inset 0 6px 1px 0 rgba(0, 0, 0, 0.35),
0 5px 5px rgba(0, 0, 0, 0.5), 0 5px 25px rgba(0, 0, 0, 0.35);
cursor: pointer;
}
.calculator .buttons span::before {
content: "";
position: absolute;
inset: 5px 3px;
border-top: 3px solid white;
filter: blur(2px);
}
.calculator .buttons span:active {
box-shadow: inset 0 2px 2px 0 rgba(0, 0, 0, 0.35),
inset 0 5px 15px 0 rgba(0, 0, 0, 0.5),
inset 0 5px 15px 0 rgba(0, 0, 0, 0.35);
text-shadow: 0 0 10px #0095ff, 0 0 8px #0095ff;
}
.calculator .buttons span#delete {
grid-column: span 2;
background: #ff685d;
color: #fff;
}
.calculator .buttons span#plus {
grid-row: span 2;
background: #53ff59;
color: #fff;
}
.calculator .buttons span#equal {
background: #ee00da;
color: #fff;
}
</style>
<body>
<div class="calculator">
<div class="buttons">
<input id="value" type="text" />
<span onclick="clsData()" id="delete">DELETE</span>
<span onclick="storeData('/')">/</span>
<span onclick="storeData('*')">*</span>
<span onclick="storeData('7')">7</span>
<span onclick="storeData('8')">8</span>
<span onclick="storeData('9')">9</span>
<span onclick="storeData('-')">-</span>
<span onclick="storeData('4')">4</span>
<span onclick="storeData('5')">5</span>
<span onclick="storeData('6')">6</span>
<span onclick="storeData('+')" id="plus">+</span>
<span onclick="storeData('1')">1</span>
<span onclick="storeData('2')">2</span>
<span onclick="storeData('3')">3</span>
<span onclick="storeData('0')">0</span>
<span onclick="storeData('00')">00</span>
<span onclick="storeData('.')">.</span>
<span onclick="calData()" id="equal">=</span>
</div>
</div>
</body>
<script>
function storeData(v) {
let value = document.getElementById("value");
let oldValue = value.value;
let t = oldValue.length;
let lastChr = oldValue[t - 1];
let oprSym = ["+", "-", "*", "/", "."];
if (oprSym.includes(v)) {
if (oprSym.includes(lastChr)) {
let removerLast = oldValue.slice(0, -1);
value.value = removerLast + v;
} else {
value.value = oldValue + v;
}
} else {
value.value = oldValue + v;
}
}
function calData(params) {
let value = document.getElementById("value");
let oldValue = eval(value.value);
value.value = oldValue;
}
function clsData() {
document.getElementById("value").value = "";
}
</script>
</html>