-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
149 lines (138 loc) · 4.57 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
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
<!doctype html>
<html manifest="cache.manifest">
<head>
<meta charset="utf-8"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>q-numbers</title>
<style>
* {
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
box-sizing: border-box;
}
html {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: black;
color: white;
}
body {
margin: 0;
padding: 0;
text-align: center;
width: 100%;
overflow: hidden;
position: fixed;
left: 0;
top: 0;
}
#numbers {
display: flex;
flex-direction: column;
justify-content: space-around;
}
.number {
font-size: 33vw;
line-height: calc(50vh - 8px);
font-weight: bold;
padding: 4px 0;
display: flex;
justify-content: space-between;
}
.number:first-child {
border-bottom: 4px solid #1c1c1c;
}
.number .button {
width: 50px;
padding: 0;
line-height: 40px;
font-size: 30px;
}
#number-red {
color: #ff4242;
}
#number-blue {
color: #4278ff;
}
.button {
background: #1c1c1c;
color: #575757;
border: 0;
cursor: pointer;
margin: 0;
z-index: 1;
}
#increment-both {
display: block;
width: 150px;
height: 150px;
border-radius: 50%;
border: 4px solid black;
padding: 0;
position: absolute;
top: calc(50% - 80px);
right: -25px;
text-align: center;
font-size: 100px;
line-height: 145px;
}
</style>
</head>
<body>
<div id="numbers">
<div class="number">
<button id="decrement-red" class="button left" aria-label="Decrement red">-</button>
<span id="number-red" aria-label="Red number">1</span>
<button id="increment-red" class="button right" aria-label="Increment red">+</button>
</div>
<div class="number">
<button id="decrement-blue" class="button left" aria-label="Decrement blue">-</button>
<span id="number-blue" aria-label="Blue number">2</span>
<button id="increment-blue" class="button right" aria-label="Increment blue">+</button>
</div>
</div>
<button id="increment-both" class="button" aria-label="Increment both">+</button>
<script>
try {
var elementRed = document.querySelector("#number-red");
var elementBlue = document.querySelector("#number-blue");
function getValue(element) {
return parseInt(element.textContent) || 0;
}
function normalize(value) {
return Math.max(value, 0);
}
function incrementBoth() {
var currentRed = getValue(elementRed);
var currentBlue = getValue(elementBlue);
var biggest = Math.max(currentRed, currentBlue)
elementRed.textContent = normalize(biggest + 1);
elementBlue.textContent = normalize(biggest + 2);
}
function changeValue(element, delta) {
var currentValue = getValue(element);
element.textContent = normalize(currentValue + delta);
}
function setValue(element) {
var currentValue = getValue(element);
var number = parseInt(prompt("Set value", currentValue));
if (number || number === 0) {
element.textContent = normalize(number);
}
}
document.querySelector("#increment-both").addEventListener('mouseup', incrementBoth);
document.querySelector("#increment-red").addEventListener('mouseup', function() { changeValue(elementRed, 1) });
document.querySelector("#decrement-red").addEventListener('mouseup', function() { changeValue(elementRed, -1) });
document.querySelector("#increment-blue").addEventListener('mouseup', function() { changeValue(elementBlue, 1) });
document.querySelector("#decrement-blue").addEventListener('mouseup', function() { changeValue(elementBlue, -1) });
elementRed.addEventListener('click', function() { setValue(elementRed); });
elementBlue.addEventListener('click', function() { setValue(elementBlue); });
} catch(e) {
document.write(e);
}
</script>
</body>
</html>