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...
This works :
function resizeText(multiplier) {
if (document.body.style.fontSize == "") {
document.body.style.fontSize = "small";
}
}
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.
Now I've done this, doesn't work either :
<script type="text/javascript">// <![CDATA[
function resizeText(multiplier) {
var tab = ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"];
if (document.body.style.fontSize === tab[0]) {
document.body.style.fontSize = tab[1];
}
else if (document.body.style.fontSize === tab[1])
{
document.body.style.fontSize = tab[2];
}
else if (document.body.style.fontSize === tab[2])
{
document.body.style.fontSize = tab[3];
}
else if (document.body.style.fontSize === tab[3])
{
document.body.style.fontSize = tab[4];
}
else if (document.body.style.fontSize === tab[4])
{
document.body.style.fontSize = tab[5];
}
else if (document.body.style.fontSize === tab[5])
{
document.body.style.fontSize = tab[6];
}
}
// </script>
<button onclick="resizeText(1)" >+</button>