我将推荐一种我已经使用过几次的 JavaScript 方式:
HTML:
<div class="foo">content to be scale to 130%</div>
<div>content that won't be scaled</div>
JavaScript:
var scale = function(target, css_rule, value)
{
var type = document.defaultView.getComputedStyle(target, "").getPropertyValue(css_rule).match(/[a-zA-Z]{0,2}$/); //Get unit type from end of string
value = (parseInt(document.defaultView.getComputedStyle(target, "").getPropertyValue(css_rule)) * value); //Get current value of css_rule and multiply by entered value
target.style.cssText += css_rule + ':' + value + type + ';'; //Add css_rule to cssText with value and type
}
然后您可以使用以下代码调用此代码:
var elem = document.getElementsByClassName('foo')[0];
scale(elem, 'font-size', 1.3);
jsFiddle of this example
此示例将类的 font-size 扩展 30%,然后您可以将其应用于您希望扩大的任何和所有 CSS 规则。
您可能想扩展我的脚本以删除已被某些 Regular Expressions 覆盖的旧 cssText 规则,您可以在此 here. 上阅读更多信息
希望对你有帮助,可能还有更简单的方法,不过这段代码可以随时调用,让你轻松放大缩小元素
注意:
这个例子使用了一种不常见的方式来获取元素的样式,Computed Style,它只适用于 Safari、Opera、Google Chrome 和 Firefox。
对于 Internet Explorer 使用:elem.currentStyle