extractDocument(document.getElementById("detailCnt"));
function extractDocument(obj) {
var childNodes = obj.childNodes;
for (var i = 0; i < childNodes.length; i++) {
var c = childNodes[i];
switch (c.nodeType) {
case 1:
extractDocument(c);
break;
case 3:
if (trim(c.nodeValue).length == 0) break;
$(".detail-main .switchsize a").click(function() {
var thisEle = getStyle(c.parentNode, "fontSize");
var textFontSize = parseFloat(thisEle, 10);
var unit = thisEle.slice(-2);
var cName = $(this).attr("class");
if (cName == "bigger") {
if (textFontSize <= 22) { //最大24px
textFontSize += 2;
}
} else if (cName == "smaller") {
if (textFontSize >= 14) { //最小12px
textFontSize -= 2;
}
} else {
textFontSize = 16; //正常16px
}
c.parentNode.style.fontSize = textFontSize + unit;
})
break;
}
}
}
function trim(str) {
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function getStyle(el, attr) {
if (window.getComputedStyle) {
return window.getComputedStyle(el, null)[attr];
}
return el.currentStyle[attr];
}
JS统一调整字体大小
最新推荐文章于 2024-04-26 16:47:03 发布