-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathindex.html
More file actions
96 lines (86 loc) · 2.8 KB
/
index.html
File metadata and controls
96 lines (86 loc) · 2.8 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>Pixel PX to VH | VW Viewport conversion</title>
</head>
<body>
<header>
<nav>
<h1>
<a href="https://github.com/khaledkzy/pixel-vh-VW-converter">Pixel PX to VH VW Viewport conversion</a>
</h1>
</nav>
</header>
<main>
<!-- 1 -->
<div>
<span class="text">Convert From px to vh</span>
<br>
<input class="pixelToVH" type="number" onkeyup="pixelToVH(this.value);">
<br>
<span class="result" id="pixelToVH">Result</span>
</div>
<!-- 2 -->
<div>
<span class="text">Convert From px to VW</span>
<br>
<input class="pixelToVW" type="number" onkeyup="pixelToVW(this.value);">
<br>
<span class="result" id="pixelToVW">Result</span>
</div>
<!-- 3 -->
<div>
<span class="text">Convert From vh to px</span>
<br>
<input class="vhToPixel" type="number" onkeyup="vhToPixel(this.value);">
<br>
<span class="result" id="vhToPixel">Result</span>
</div>
<!-- 4 -->
<div>
<span class="text">Convert From VW to px</span>
<br>
<input class="vwToPixel" type="number" onkeyup="vwToPixel(this.value);">
<br>
<span class="result" id="vwToPixel">Result</span>
</div>
</main>
<footer id="footer">
Copyright (c) 2018
<a href="https://khaledkzy.github.io/pixel-vh-vw-converter/">
<strong>Pixel PX to VH VW Viewport conversion</strong>
</a> / To view the
<a href="https://github.com/khaledkzy/pixel-vh-VW-converter">
<strong>Source Code</strong>
</a>
</footer>
</body>
<script>
function pixelToVH(value) {
return document.querySelector("#pixelToVH").innerHTML = `Result = ${(100 * value) / window.innerHeight}vh`;
}
function pixelToVW(value) {
return document.querySelector("#pixelToVW").innerHTML = `Result = ${(100 * value) / window.innerWidth}vw`;
}
function vhToPixel(value) {
return document.querySelector("#vhToPixel").innerHTML = `Result = ${(window.innerHeight * value) / 100}px`;
}
function vwToPixel(value) {
return document.querySelector("#vwToPixel").innerHTML = `Result = ${((window.innerWidth * value) / 100)}px`;
}
window.addEventListener('resize', updateMeasurements)
function updateMeasurements() {
const pixelToVHValue = document.querySelector('.pixelToVH').value
const pixelToVWValue = document.querySelector('.pixelToVW').value
const vhToPixelValue = document.querySelector('.vhToPixel').value
const vwToPixelValue = document.querySelector('.vwToPixel').value
pixelToVH(pixelToVHValue)
pixelToVW(pixelToVWValue)
vhToPixel(vhToPixelValue)
vwToPixel(vwToPixelValue)
}
</script>
</html>