<html>
<head>
<script language="javascript">
var minFont = 8;
var maxFont = 18;
function changeFontSize (addedSize) {
// Get the current font size
var currentFontSize = document.getElementById("mytext").style.fontSize;
// Strip off the units, and the px
currentFontSize = parseFloat(currentFontSize);
// If the current fontSize is bigger than the max allowed, set it to
// the max
if (currentFontSize + addedSize > maxFont)
document.getElementById("mytext").style.fontSize = maxFont + 'px';
// If the current fontSize is smaller than the min allowed, set it to
// the min
else if (currentFontSize + addedSize < minFont)
document.getElementById("mytext").style.fontSize = minFont + 'px';
// Otherwise, just add the delta to the current size
else
document.getElementById("mytext").style.fontSize = currentFontSize + addedSize + 'px';
}
</script>
</head>
<body>
<h3>TEXT-SHRINKING and TEXT-GROWING Demo</h3>
Text:
<div id="mytext" style="font-size:14px;">
www.CodeRevise.com
</div>
<p>
<button onclick="changeFontSize(1);">Grow</button>
<button onclick="changeFontSize(-1);">Shrink</button>
</p>
</body>
</html>