-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
38 lines (33 loc) · 920 Bytes
/
index.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
var viewport = require('viewport')
var merge = require('merge')
/**
* init flowtype on `el`
*
* @param {Element} el
* @param {Object} [options]
* @api public
*/
module.exports = function(el, options){
options = merge({
min: 14,
max: 18,
lineRatio: 1.45,
minWidth: getComputedStyle(el).minWidth,
maxWidth: getComputedStyle(el).maxWidth
}, options)
var minWidth = parseFloat(options.minWidth)
var maxWidth = parseFloat(options.maxWidth)
var widthDiff = maxWidth - minWidth
var fontMin = options.min
var fontDiff = options.max - fontMin
var lineRatio = options.lineRatio
function resize(){
var width = parseFloat(getComputedStyle(el).width)
var percent = (width - minWidth) / widthDiff
var font = fontMin + (fontDiff * percent)
el.style.lineHeight = font * lineRatio + 'px'
el.style.fontSize = font + 'px'
}
viewport.addListener(resize)
resize()
}