获取元素重置为默认大小后字体增大/减小
问题描述:
如何让我的页面上的元素,以重置后的字体增加违约/减少获取元素重置为默认大小后字体增大/减小
我试过以下,但收效甚微(字体增加/减少工作):
这里是我的代码:
$(".resetFont").click(function() {
});
$(".increaseFont").click(function() {
var fontSize = getFontSize();
var newFontSize = fontSize + 1;
setFontSize(newFontSize);
return false;
});
$(".decreaseFont").click(function() {
var fontSize = getFontSize();
var newFontSize = fontSize - 1;
setFontSize(newFontSize);
return false;
});
function getFontSize() {
var currentSize = $("html").css("font-size");
var currentSizeNumber = parseFloat(currentSize, 12);
if (currentSizeNumber > 24) {
currentSizeNumber = 24;
}
if (currentSizeNumber < 10) {
currentSizeNumber = 10;
}
return currentSizeNumber;
}
function setFontSize(size) {
$("html").css("font-size", size);
$(".actualSize").html(size);
}
答
var defaultFontSize = $('html').css('font-size');
$(".resetFont").click(function() {
$('html').css('font-size', defaultFontSize);
});
答
var defaultFontSize = $('html').css('font-size');
$(".resetFont").click(function() {
$("html").css("font-size", defaultFontSize);
$(".actualSize").html(defaultFontSize);
});
答
只需设置你想要的原始字体大小是什么:
$(".resetFont").click(function() {
$("html").css("font-size", '24px');
});
答
$('.resetFont').click(function(){
setFontSize('auto');
}
真的没人了吗?
'12'应该在'parseFloat(currentSize,12);'中? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat – 2015-12-22 21:39:34