I'm trying to add some text resize functionality using this code:
$('#text-resize a').click(function(){
var currentValue = $('#page-body').css('fontSize');
var currentSize = parseFloat(currentValue, 10);
var fontUnit = currentValue.slice(-2);
var newSize = currentSize;
if ($(this).attr('rel') == 'decrease'){
if (currentSize > 13){
var newSize = currentSize / 1.2;
}
}
else if ($(this).attr('rel') == 'increase'){
if (currentSize < 19){
var newSize = currentSize * 1.2;
}
}
else {
newSize = 1;
fontUnit = 'em';
}
newSize += fontUnit;
$('#page-body').css('fontSize', newSize);
return false;
});
I know it's not the cleanest code, but my problem is that at some point (either getting or setting the font size for #page-body
decimal points are being lost.
For example, I start with a value of 16px (from my CSS file) and when I increase it gets calculated to 19.2px. If I increase again, an alert of the currentValue (I have left out the alert) says it's 19px.
Can anyone tell me why decimal places are being ignored and how to prevent that?
If it helps, my starting CSS includes:
body { font-size: 16px; }
#page-body { font-size: 1em; }
Thanks