智能文字大小 PHP

根据页面的宽度自动调正字体大小

haha 中文测试

haha

代码:

<p id="pp1">haha 中文测试</p>
<p>haha</p>
<span id="span1"></span>
<script type="text/javascript">
function zoomFontSize()
{
var allWidth = document.documentElement.clientWidth;
var newFontSize = pp1.oldFontSize * allWidth / 1024;
newFontSize
= Math.min(100, newFontSize);
newFontSize
= Math.max(12, newFontSize);
pp1.style.fontSize
= newFontSize + 'px';
document.getElementById(
'span1').innerHTML = pp1.style.fontSize;
}

var pp1 = document.getElementById('pp1');
window.onresize
= zoomFontSize;
var fontSize = document.all?pp1.currentStyle['fontSize']:document.defaultView.getComputedStyle(pp1,false)['fontSize'];

pp1.oldFontSize
= parseInt(fontSize);
zoomFontSize();
alert(document.documentElement.offsetHeight);
</script>




欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
原文地址:https://www.cnblogs.com/zjfree/p/2219242.html