-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
66 lines (53 loc) · 2.13 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Element Size Calculator</title>
<script>
function calculateSize() {
// Get the selected dimension from the form
var dimension = document.getElementById("dimension").value;
// Get the element width or height from the form
var size = document.getElementById("size").value;
// Calculate and displaythe percentage value based on the input
if (dimension === "width") {
var percentage = (size / 1440) * 100;
document.getElementById("result").innerHTML = "The percentage value is: " + percentage.toFixed(2) + "%";
} else if (dimension === "height") {
var percentage = (size / 3347) * 100;
document.getElementById("result").innerHTML = "The percentage value is: " + percentage.toFixed(2) + "%";
} else {
document.getElementById("result").innerHTML = "Invalid input!";
}
// Set the value of the hidden input field to the calculated percentage value
document.getElementById("percentage").value = percentage.toFixed(2);
}
function copyPercentage() {
// Get the value of the hidden input field
var percentage = document.getElementById("percentage").value;
// Append the percent symbol to the value
var valueWithSymbol = percentage + "%";
// Copy the value to the clipboard
navigator.clipboard.writeText(valueWithSymbol);
}
</script>
</head>
<body>
<form>
<label for="dimension">Width or Height:</label>
<select id="dimension" name="dimension">
<option value="width">Width</option>
<option value="height">Height</option>
</select>
<br>
<label for="size">Enter your element size:</label>
<input type="number" id="size" name="size">
<br>
<button type="button" onclick="calculateSize()">Calculate</button>
<br>
<input type="hidden" id="percentage">
<button type="button" onclick="copyPercentage()">Copy</button>
</form>
<p id="result"></p>
</body>
</html>