I created a function to calculate the font size to fit the width of the website I'm doing. I believe the code is a bit ugly and could use some improvement by creating a more logical function, faster and less heavy.
Can someone look at the code and comment on it for my own improvement?
//Script jquery
$(window).resize(function() {
newWidthGhost = $('#ghostFontes').width();
widthFontsResize();
});
$(document).ready(function(){
$('body').find('*').addClass('wFonte');
$('.wFonte').each(function(i, el){
fontHeight[i] = $(el).css('font-size');
});
oldWidthGhost = $('#ghostFontes').width(); // TAMANHO WIDTH;
widthFontsReady();
});
function widthFontsResize(){
$('.wFonte').each(function(i, el){
nFonte['e'+i] = parseInt((newWidthGhost * nFonte[i]) / oldWidthGhost);
$(el).css({'font-size': nFonte['e'+i]+'px'});
});
}
function widthFontsReady(){
$('.wFonte').each(function(i, el){
nFontHeigth[i] = parseInt(fontHeight[i].substr(0,2));
nFonte[i] = parseInt((oldWidthGhost * nFontHeigth[i]) / 1586);
$(el).css({'font-size': nFonte[i]+'px'});
});
}