-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
123 lines (95 loc) · 3.35 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
<html>
<head>
<title></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<input type="range" id="baseSize" min="10" max="40">
<p id="baseSizeLabel">16pt</p>
<a href="#" class="button" id="rangeUp">/\</a>
<a href="#" class="button" id="rangeDown">\/</a>
<ul>
<li>
<span class="label body">Small<span class="size"></span></span>
<span class="sample small">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">Body<span class="size"></span></span>
<span class="sample body">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">H4<span class="size"></span></span>
<span class="sample h4">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">H3<span class="size"></span></span>
<span class="sample h3">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">H2<span class="size"></span></span>
<span class="sample h2">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">H1<span class="size"></span></span>
<span class="sample h1">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">Big<span class="size"></span></span>
<span class="sample big">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">Bigger<span class="size"></span></span>
<span class="sample bigger">Lorem ipsum dolor sit amet</span>
</li>
<li>
<span class="label body">Biggest<span class="size"></span></span>
<span class="sample biggest">Lorem ipsum dolor sit amet</span>
</li>
</ul>
<script type="text/javascript">
var samples = document.querySelectorAll('.sample')
var labels = document.querySelectorAll('.label')
var body = document.querySelector('body, html')
var initialSize = getComputedStyle(body).getPropertyValue('font-size')
var sizes = document.querySelectorAll('.size')
var buttons = document.querySelectorAll('.button')
var slider = document.querySelector('#baseSize')
function initialize() {
slider.setAttribute("value", parseInt(initialSize))
document.querySelector('#baseSizeLabel').innerHTML = initialSize
slider.addEventListener('change', changeSizes)
getSizes()
}
var getSizes = function() {
for(var i = 0; i < samples.length; i++) {
var fontSize = parseFloat(getComputedStyle(samples[i]).getPropertyValue('font-size'), 10)
fontSize = Math.round(fontSize)
var leading = parseFloat(getComputedStyle(samples[i]).getPropertyValue('line-height'), 10)
leading = Math.round(leading)
sizes[i].innerHTML = fontSize + "/" + leading
}
}
var changeSizes = function() {
var newSize = slider.value
body.style.fontSize = newSize + "px"
document.querySelector('#baseSizeLabel').innerHTML = newSize + "px"
getSizes()
}
for(var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", function(e) {
e.preventDefault()
var buttonID = this.getAttribute("id")
if(buttonID == "rangeUp") {
slider.value ++
changeSizes()
}
else if(buttonID == "rangeDown") {
slider.value --
changeSizes()
}
})
}
initialize()
</script>
</body>
</html>