Webmonkey
Powered by Atomz.com



Quick Reference:

• Javascript Code Library
HTML Cheatsheet
Special Characters
Color Codes
Browser Chart
Stylesheet Guide
Unix Guide
Glossary
Domain Registries

Reference   JavaScript Code Library

WM_scaleFont() scales the fonts on the page depending on the width of the window. It's very useful for creating a page that's designed to fit within a window without scrolling. For the whole effect to work well, use relative units (em, ex, %) for all your CSS positioning and for image and DIV sizes.

Usage: WM_scaleFont(targetSize, initialFontSize, fontUnits);

The targetSize is the window size for which you designed your page. The initialFontSize is the size you want for default text when the window is at the targetSize. The fontUnits are the units (pt or px) of your initial body tag.

Internet Explorer requires the body tag to be loaded before you can determine the width, and Netscape needs to call the function in the head to write out the style tag. So you need to insert two calls: one in a script tag in the head, after any style sheets, and the other in a script tag right after the body.

<head>
<script>
if (document.layers)
  WM_scaleFont(targetSize, initialFontSize, fontUnits);
</script>
</head>
<body>
<script>
if(document.all){
WM_scaleFont(targetSize, initialFontSize, fontUnits);
}
</script>

All fonts that you wish to scale must be in a relative CSS unit (em, ex, %). This refers to their size relative to the default body font size. For example, if you've set the default font to be 40px and you specify some other text to be 50%, it will be 20px when the window is open to the targetSize and 10px when the window is open to half the targetSize.

Requires: WM_netscapeCSSResizeFix()

License: Webmonkey Public License

Cut, paste, and enjoy!


Feedback  |  Help  |  About Us  |  Contribute  |  Jobs
Advertise  |  Privacy Statement  |  Terms and Conditions

Copyright © 1994-2000 Wired Digital Inc., a Lycos Network site. All rights reserved.