Created
July 15, 2011 07:01
-
-
Save NigelThorne/1084223 to your computer and use it in GitHub Desktop.
Resize fonts on a webpage to make things visible from a distance.
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
// 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