Skip to content

Instantly share code, notes, and snippets.

@paulkaplan
Created August 4, 2011 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulkaplan/1124211 to your computer and use it in GitHub Desktop.
Save paulkaplan/1124211 to your computer and use it in GitHub Desktop.
Scaling $(body) font-size to window size
$(document).ready(function() {
var $body = $('body'); //Cache this for performance
var setBodyScale = function() {
var scaleSource = $body.width(),
scaleFactor = 0.9,
maxScale = 1000,
minScale = 30;
var fontSize = scaleSource * scaleFactor;
if (fontSize > maxScale) fontSize = maxScale;
if (fontSize < minScale) fontSize = minScale;
$('body').css('font-size', fontSize + '%');
}
$(window).resize(function(){
setBodyScale();
});
//Fire it when the page first loads:
setBodyScale();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment