-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
40 lines (35 loc) · 1.37 KB
/
script.js
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
var input = document.getElementById("valor");
var select = document.getElementById("unidades");
var divResultado = document.getElementById("valorConvertido");
input.addEventListener("input", calcular);
select.addEventListener("change", calcular);
function calcular() {
var valorInput = Number(input.value);
var valorSelect = select.value;
if (valorInput === 0) {
divResultado.innerHTML = "Enter a valid number";
} else {
var valorEmKm = valorInput * (9.46 * 10 ** 12);
var valorEmM = valorInput * (9.4607 * 10 ** 15);
switch (valorSelect) {
case "km":
divResultado.innerHTML = `${valorEmKm} km<br>ou<br>${valorInput} × <strong>9.46×10<sup>12</sup></strong> km`;
break;
case "m":
divResultado.innerHTML = `${valorEmM} m<br>ou<br>${valorInput} × <strong>9.4607×10<sup>15</sup></strong> m`;
break;
}
}
}
document.body.setAttribute("onmousemove", "moverFundo(event)");
document.body.setAttribute("ontouchmove", "moverFundoTouch(event)");
function moverFundo(event) {
document.body.style.backgroundPositionX = -event.clientX / 100 + "px";
document.body.style.backgroundPositionY = -event.clientY / 100 + "px";
}
function moverFundoTouch(event) {
document.body.style.backgroundPositionX =
-event.touches[0].clientX / 30 + "px";
document.body.style.backgroundPositionY =
-event.touches[0].clientY / 30 + "px";
}