Skip to content

Instantly share code, notes, and snippets.

@yec
Created October 25, 2012 03:31
Show Gist options
  • Save yec/3950266 to your computer and use it in GitHub Desktop.
Save yec/3950266 to your computer and use it in GitHub Desktop.
fontsize
(function($) {
var min = 8;
var max = 18;
DECREASE = 1;
INCREASE = 2;
function fontSize(size) {
var dofont = function(ele) {
var s = parseInt($(ele).css('font-size').replace(/px/, ''));
var l = parseInt($(ele).css('line-height').replace(/px/, ''));
if (size == DECREASE && s > min) {
s -= 1;
l -= 1;
} else if (size == INCREASE && s < max) {
s += 1;
l += 1;
}
$(ele).css('font-size', s + 'px');
$(ele).css('line-height', l + 'px');
};
var applyto = [
$('#content-body').find('p'), $('#content-body').find('h3'), $('#content-body').find('li'), $('#content-body').find('h2'), $('#content-body').find('h1')];
for (selector in applyto) {
applyto[selector].each(function() {
dofont(this);
});
}
}
$(function() {
$('#increaseFont').click(function() {
fontSize(INCREASE);
});
$('#decreaseFont').click(function() {
fontSize(DECREASE);
})
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment