Skip to content

Instantly share code, notes, and snippets.

@NigelThorne
Created July 15, 2011 07:01
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 NigelThorne/1084223 to your computer and use it in GitHub Desktop.
Save NigelThorne/1084223 to your computer and use it in GitHub Desktop.
Resize fonts on a webpage to make things visible from a distance.
// Mark things you want to resize with class="resizeable"
// The ratio between their sizes will be maintained.
// works with jquery-1.4.2.min.js
//
// <script src=".../jquery-1.4.2.min.js"></script>
// <script src=".../resize.js"></script>
//
function resizeNodes(nodes, startsizes, multiplier){
var newsizes = startsizes.map(function(item, index){return item * multiplier;});
nodes.each(function(index){$(this).css('font-size',newsizes[index]);});
};
function resize() {
var multiplier = 1.0;
var nodes = $(".resizeable");
var startsizes = nodes.map(function(){return parseFloat($(this).css('font-size'),10);}).get();
while ($(document).height()<=($(window).height()))
{
multiplier += 0.5;
resizeNodes(nodes, startsizes, multiplier);
};
while ($(window).height()<$(document).height()&& multiplier > 0.5)
{
multiplier -= 0.01;
resizeNodes(nodes, startsizes, multiplier);
};
while ($(window).width()<$(document).width() && multiplier > 0.5)
{
multiplier -= 0.05;
resizeNodes(nodes, startsizes, multiplier);
};
};
$(document).ready(resize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment