Repository navigation
Expand file tree
/
Copy pathdensity-calc.html
More file actions
183 lines (158 loc) · 5.05 KB
/
Copy pathdensity-calc.html
File metadata and controls
183 lines (158 loc) · 5.05 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Density Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 40px;
max-width: 1200px;
width: 100%;
margin: 20px;
justify-content: space-between;
}
.column {
background-color: #fff;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
width: 48%;
box-sizing: border-box;
}
@media (max-width: 768px) {
.column {
width: 100%;
margin-bottom: 20px;
}
}
h3 {
font-size: 1.5rem;
margin-bottom: 20px;
}
label, input, button {
display: block;
margin-bottom: 10px;
width: 100%;
}
input {
padding: 10px 20px; /* Equal padding on both sides */
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
button {
background-color: #000;
border: none;
color: white;
padding: 10px;
text-align: center;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
margin-top: 10px;
}
button:hover {
background-color: #333;
}
#result {
font-weight: bold;
margin-top: 20px;
text-align: center;
}
#embed-code {
width: 100%;
height: 100px;
margin-bottom: 10px;
}
#toast {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
transform: translateX(-50%);
}
#toast.show {
visibility: visible;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
</style>
</head>
<body>
<div class="container">
<div class="column">
<h3>Density Calculator</h3>
<form id="densityForm" onsubmit="calculateDensity(event)">
<label for="mass">Mass (kg):</label>
<input type="number" id="mass" required>
<label for="volume">Volume (m³):</label>
<input type="number" id="volume" required>
<button type="submit">Calculate</button>
<button type="reset" onclick="resetForm()">Reset</button>
</form>
<div id="result" style="display: none;"></div>
</div>
<div class="column">
<h3>Embed Code</h3>
<textarea id="embed-code" readonly><iframe src="https://cbemstar.github.io/calculator/density-calc.html" width="100%" height="600" frameborder="0"></iframe></textarea>
<button onclick="copyEmbedCode()">Copy Embed Code</button>
</div>
</div>
<div id="toast">Embed code copied to clipboard!</div>
<script>
function calculateDensity(event) {
event.preventDefault();
const mass = parseFloat(document.getElementById('mass').value);
const volume = parseFloat(document.getElementById('volume').value);
if (isNaN(mass) || isNaN(volume) || mass <= 0 || volume <= 0) {
alert("Please enter valid numbers for all fields.");
return;
}
const density = mass / volume;
document.getElementById('result').innerHTML = `Density: ${density.toFixed(2)} kg/m³`;
document.getElementById('result').style.display = 'block';
}
function resetForm() {
document.getElementById('result').style.display = 'none';
}
function copyEmbedCode() {
const embedCode = document.getElementById('embed-code');
embedCode.select();
document.execCommand('copy');
showToast();
}
function showToast() {
const toast = document.getElementById('toast');
toast.className = 'show';
setTimeout(() => { toast.className = toast.className.replace('show', ''); }, 3000);
}
</script>
</body>
</html>