background
|
|
Tombstone
Tombstone Tuning
Home of tuning, projects and fast cars and boats.
More icon

Computer
|
|
Up Image
Navigation
Search this Site
Enter your search terms

Site Breadcrumb - You are here
|
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()

Cut, paste, and enjoy!