我有一些用户提示我的 Web 应用程序上的字体太小而无法阅读。他们对尝试在浏览器上调整字体设置不满意,因为当他们使字体变大时,应用程序的尺寸和布局也会发生变化。有没有现成的工具可以让最终用户选择小号/中号/大号字体,并在不影响页面布局的情况下将网站的 .css 更改为更大的字体?
最佳答案
这是我在我的一些网站上使用的代码。相应地应用您的 HTML:
HTML:
<span>Font Size: </span>
<a href="#" onclick="decreaseFontSize();">
<img src="/images/minus.png" alt="Decrease Font Size" />
</a>
<a href="#" onclick="increaseFontSize();">
<img src="/images/plus.png" alt="Increase Font Size" />
</a>
Javascript:
var min=8;
var max=18;
function increaseFontSize() {
p = document.getElementById("[the id of container w/font you want to size]");
if(p.style.fontSize) {
var s = parseInt(p.style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=max) {
s += 1;
}
p.style.fontSize = s+"px"
}
function decreaseFontSize() {
p = document.getElementById("[the id of container w/font you want to size]");
if(p.style.fontSize) {
var s = parseInt(p.style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=min) {
s -= 1;
}
p.style.fontSize = s+"px"
}
关于jquery - 我怎样才能使我网站上的字体更大并且更易于某些用户阅读?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1792371/