[thelist] dynamic font size

Árni Gunnar Ragnarsson arnigunnar at gmail.com
Tue Jul 12 03:54:17 CDT 2005


These are the functions I use. Basically you set the font size on the
body, and every item inherits its font size from the body. When you
change the font size by JavaScript on the body, the rest of the
content follows.

I store the info in a cookie for future visits of the user and for all
the reloads.

function enlargeFont() {
	var size = getCookie("CookieName");
	if (size == null) {
		size = 11;
	}
	size++;
	if (size > 15) {size = 15}
	document.body.style.fontSize = getPercentSize(size)+'%';
	setCookieCookieName",size);
}

function shrinkFont() {
	var size = getCookie("CookieName");
	if (size == null) {
		size = 11;
	}
	size--;
	if (size < 9) {size = 9}
	document.body.style.fontSize = getPercentSize(size)+'%';
	setCookie("CookieName",size);
}

function getPercentSize(size) {
	return (size/16)*100;
}

function initDoc() {
	var fontSize = "11";
	if ((getCookie("CookieName") != null) &&  (getCookie("CookieName") != '')) {
		fontSize =  getCookie("CookieName");
	}
	if (fontSize != 11) {
		document.body.style.fontSize = getPercentSize(fontSize) + "%";
	}
}


More information about the thelist mailing list