Your script is broken in many ways.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
The latest version of HTML is 4.01, and the "transitional" phase was over a good decade ago.This doesn't need to be global.
function ChangeSyle(SomeTag)
Javascript convention is that variables and functions start with a lower-case letter, unless they're constructor functions or namespacing objects.i what? Centimetres? Inches? Pixels? Ems? How long does it take me to walk to the butchers if I walk at twelve and the butchers' is three away?
tme=setTimeout("ChangeSyle()",50)
Passing strings to setTimeout() is ugly and inefficient. Also, you don't pass the SomeTag parameter that you later use in the function. This is the cause of your error.
Style this paragraph in 14pt bold red text.
Points are an absolute measurement (1/72th of an inch) and so do not scale well on differently-sized displays. You should use a relative measurement, such as percentages.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Enlarge Text</title>
<script type="text/javascript">
function defaultArgs(opts, defaults) {
opts = opts || {};
defaults = defaults || {};
for(var x in opts)
if(typeof opts[x] === "undefined")
opts[x] = defaults[x];
return opts;
}
function growElement(element, opts) {
opts = defaultArgs(opts, {
start: 0,
stop: 100,
step: 5,
units: "em"
});
var c = opts.start,
s = element.style,
p = function() {
if(c >= opts.stop) {
clearInterval(t);
s = null;
} else {
s.width = c + opts.units;
c += opts.step;
}
},
t = setInterval(p, 50);
element = null;
}
function changeStyle(el) {
var s = el.style;
s.fontSize = "150%";
s.fontWeight = "bold";
s.color = "red";
growElement(el);
}
</script>
</head>
<body>
<p onclick="changeStyle(this);">Style this paragraph in 150% bold red text.</p>
</body>
</html>
Untested.
Bookmarks