Crystal
Crystal

Reputation: 1

Javascript Text Resize Problems

I am attempting to use a java script text resize function on a website. But, it is not working. I wonder if any one can spot a coding error that I am not seeing? Thanks!

http://sample.myblackhairstyle.com/ (resizer is in top right hand corner "Make Text Bigger).

In header.php I put:

    <script type="text/javascript">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";
}</script>`

Place this where wanted resizer to appear:

Make text bigger | Make text smaller

Upvotes: 0

Views: 240

Answers (2)

musicnothing
musicnothing

Reputation: 3985

Try replacing the resizeText function with this one:

function resizeText(multiplier) {
    if (document.body.style.fontSize == "") {
        document.body.style.fontSize = "1.0em";
    }
    document.body.style.setProperty(
        "font-size", 
        parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em",
        "important"
    );
}

Here's an example.

Anyone know how to get the initial font size of the body element as defined in css?

Upvotes: 1

Jaydev
Jaydev

Reputation: 435

I can see an error 'Uncaught SyntaxError: Unexpected token < '

while loading the website from the file 'widgets.js:1' . Firstly you need to work around that.

Upvotes: 1

Related Questions