I have a text area which is editable. When we enter text in the textArea, the font size of the text change with the change in the text length. The greater the text length, smaller the font-size. This causes problems in the justification, is there any way I can justify the text inside the text area.
Here is the JavaScript Code:
var textie = document.getElementById('new1');
var spanny = document.getElementById('length');
var textLength;
textie.addEventListener('keypress',function(e){
var size;
textLength = textie.value.length;
size = Change(textLength);
this.style.fontSize = size;
},false);
function Change(fontLength)
{
var fontSize;
if(fontLength>=1 && fontLength<=4)
{
fontSize = 35+"px";
}
else if(fontLength>=5 && fontLength<=12)
{
fontSize = 30+"px";
}
else if(fontLength>=13 && fontLength<=35)
{
fontSize = 20+"px";
}
else if(fontLength>=36 && fontLength<=50)
{
fontSize = 18+"px";
}
else if(fontLength>=51 && fontLength<=150)
{
fontSize = 16+"px";
}
else if(fontLength>150)
{
fontSize = 15+"px";
}
return fontSize;
}
Here is the HTML
<textArea class = "new" id = "new1"></textArea>
<span id = "length"></span>
I am attaching a jsfiddle, try adding (lots of) random text in it and you will understand
Thanks!