Created
October 25, 2012 03:31
-
-
Save yec/3950266 to your computer and use it in GitHub Desktop.
fontsize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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