Created
August 4, 2011 00:13
-
-
Save paulkaplan/1124211 to your computer and use it in GitHub Desktop.
Scaling $(body) font-size to window size
This file contains 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
$(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
credit comes from http://stackoverflow.com/questions/5358183/is-it-possible-to-dynamically-scale-text-size-based-on-browser-width