Reply
Fri 5 Jun, 2015 02:10 am
Hi everyone, I've got a problem with changing the font-size. I've tried a few methods like this :
function resizeText(multiplier) {
if (document.body.style.fontSize == "") {
document.body.style.fontSize = "1.0em";
}
document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
}
but it didn't work because I'm working on a website that's been made by professionnals and they didn't use em but the values xx-small, small, large... so I started doing strange stuff like this :
function resizeText(multiplier){
var tab = ["xx-small", "x-small", "small", "medium", "large"," x-large", "xx-large"];
if (document.body.style.fontSize == "") {
switch(tab){
case 'xx-small':
document.body.style.fontSize = "x-small";
break;
case 'x-small':
document.body.style.fontSize = "small";
break;
and so on...
}
}
The only thing that worked in my switch was the default value I put to the font-size.
Then I don't think that putting an array inside a switch is a good idea, I've been thinking about looping or using if/else but somehow I just can't find the answer. I keep doing strange stuff. So if someone could guide me in the right direction, I'dd be gratefull.