forked from alex-y-kuznetsov/Font-Size
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (23 loc) · 1.2 KB
/
Copy pathscript.js
File metadata and controls
32 lines (23 loc) · 1.2 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
'use strict'
var heading = document.getElementById('heading');
var para = document.getElementById('paragraph');
var calcFontSize = function () {
var headingWidth = Math.round(getComputedStyle(heading).width.slice(0, -2)); // текущая ширина
var headingSize = +getComputedStyle(heading).fontSize.slice(0, -2); // размер h1
var paraWidth = Math.round(getComputedStyle(para).width.slice(0, -2)); // ширина колонки
if(headingWidth > paraWidth){
for(var i=headingSize*10; headingWidth > paraWidth; --i){
document.getElementById('heading').style.fontSize = i/10 + "px";
paraWidth = Math.round(getComputedStyle(para).width.slice(0, -2)); // ширина колонки
headingWidth = Math.round(getComputedStyle(heading).width.slice(0, -2)); // текущая ширина
}
}else{
for(var i=headingSize*10; headingWidth < paraWidth; ++i){
document.getElementById('heading').style.fontSize = i/10 + "px";
paraWidth = Math.round(getComputedStyle(para).width.slice(0, -2)); // ширина колонки
headingWidth = Math.round(getComputedStyle(heading).width.slice(0, -2)); // текущая ширина
}
}
}
calcFontSize();
// Математика сложно