asp学习网: 首页 >> javascript教程 >> javascript实例 >> javascript改变容器内的字体大小

javascript改变容器内的字体大小

一段js,定义容器和字体的大小,实现网页容器和字体的自定义大小。

<script type="text/javascript">
<!--
function scaleWidth()
{
var optimalLineLength = "35em";
var extraAccounting = "12em";
var minimumTextHeight = "10px";
var windowWidth = document.body.clientWidth;
var optimalSize = windowWidth / (parseInt(optimalLineLength) + parseInt(extraAccounting));

if (optimalSize >= parseInt(minimumTextHeight))
{
document.body.style.fontSize = optimalSize + "px";
}
else
{
document.body.style.fontSize = parseInt(minimumTextHeight) + "px";
}

return true;
}

function textSize(size)
{
var theContainer = document.getElementById("widthContainer");
var increment = 0.1
var currentSize = parseFloat(document.getElementById("widthContainer").style.fontSize);

if (!currentSize)
{
currentSize = 0.8;
}

if (size == "smaller")
{
theContainer.style.fontSize = (currentSize - increment) + "em";
}
else
{
theContainer.style.fontSize = (currentSize + increment) + "em";
}

return true;
}
-->
</script> 
 

from:asp学习网/title:javascript改变容器内的字体大小/ time:2007-3-9 21:19:04

本文主题javascript改变容器内的字体大小

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行