-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (65 loc) · 2.37 KB
/
script.js
File metadata and controls
83 lines (65 loc) · 2.37 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
const fromInput = document.querySelector('#from');
const toInput = document.querySelector('#to');
const goButton = document.querySelector('#go');
const codePointDiv = document.querySelector('.codePoint');
const next100Btn = document.querySelector('#next100');
const fontRangeInput = document.querySelector('#fontRange');
const before100Btn = document.querySelector('#before100')
goButton.addEventListener('click', refresh);
next100Btn.addEventListener('click', () => {
next100();
refresh();
});
before100Btn.addEventListener('click', () => {
before100();
refresh();
})
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight') {
next100();
}
if (e.key === 'ArrowLeft') {
before100();
}
refresh();
});
fontRangeInput.addEventListener('input', (event) => {
const numberElements = document.querySelectorAll('.number');
const contentElements = document.querySelectorAll('.content');
numberElements.forEach(element => {
const fontSize = Number(event.target.value);
element.style.fontSize = fontSize - 10 + 'px';
});
contentElements.forEach(element => {
const fontSize = Number(event.target.value);
element.style.fontSize = fontSize + 5 + 'px';
});
})
function refresh() {
codePointDiv.textContent = '';
const fontSize = fontRangeInput.value;
for (let i = Number(fromInput.value); i < Number(toInput.value); i++) {
const elem = String.fromCodePoint(i);
let elemDiv = document.createElement('div');
elemDiv.classList.add('element');
let numberElem = document.createElement('div');
numberElem.classList.add('number');
numberElem.textContent = i;
numberElem.style.fontSize = Number(fontSize) - 10 + 'px';
let contentElem = document.createElement('div');
contentElem.classList.add('content');
contentElem.textContent = elem;
contentElem.style.fontSize = Number(fontSize) + 10 + 'px';
elemDiv.append(numberElem);
elemDiv.append(contentElem);
codePointDiv.appendChild(elemDiv);
}
}
function next100() {
fromInput.value = +toInput.value;
toInput.value = +toInput.value + 100;
}
function before100() {
toInput.value = +fromInput.value === 0 ? 100 : +fromInput.value;
fromInput.value = +fromInput.value - 100 < 0 ? 0 : +fromInput.value - 100;
}