lepisi-pengumuman/assets/js/others/fitText.js

33 lines
1.1 KiB
JavaScript

var fitText = {
fitAll: function(cl) {
var elFS, elH
cl = document.getElementsByClassName(cl)
var h = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight
// console.log(h, window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
for (var i = 0; i < cl.length; i++) {
elFS = parseInt(window.getComputedStyle(cl[i].children[0]).fontSize)
cl[i].children[0].style.fontSize = elFS + 'px'
elH = parseInt(window.getComputedStyle(cl[i].children[0]).height)
while (elH < h - (h*.15)) {
elFS++
cl[i].children[0].style.fontSize = elFS + 'px'
elH = parseInt(window.getComputedStyle(cl[i].children[0]).height)
}
while (elH > h - (h*.15)) {
elFS--
cl[i].children[0].style.fontSize = elFS + 'px'
elH = parseInt(window.getComputedStyle(cl[i].children[0]).height)
}
}
return true
}
}
module.exports = fitText