【发布时间】:2015-05-09 14:32:36
【问题描述】:
我在 javascript 中有 4 个函数用于增加字体大小和减小字体大小、增加行间距和减少行间距。 这些功能运行良好,但是如果我将字体大小增加 2 倍,然后点击减小行距,行距会增加!!
我太困惑了,任何帮助将不胜感激。
$('#incFont').on('click', function()
{
var style = getComputedStyle(document.body);
if (style.fontSize.match(/px$/) === null)
{
document.body.style.fontSize = "1.0em";
}
document.body.style.fontSize = (parseFloat(style.fontSize) * 1.2 / 16) + "em";
});
$('#decFont').on('click', function()
{
var style = getComputedStyle(document.body);
if (style.fontSize.match(/px$/) === null)
{
document.body.style.fontSize = "1.0em";
}
document.body.style.fontSize = (parseFloat(style.fontSize) * 0.8 / 16) + "em";
});
$('#incLine').on('click', function()
{
var style = getComputedStyle(document.body);
if (style.lineHeight.match(/px$/) === null)
{
document.body.style.lineHeight = "1.0em";
}
document.body.style.lineHeight = (parseFloat(style.lineHeight) * 1.2 / 16) + "em";
});
$('#decLine').on('click', function()
{
var style = getComputedStyle(document.body);
if (style.lineHeight.match(/px$/) === null)
{
document.body.style.lineHeight = "1.0em";
}
document.body.style.lineHeight = (parseFloat(style.lineHeight) * 0.8 / 16) + "em";
});
【问题讨论】:
标签: javascript html css