Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
Created February 3, 2011 02:39
Show Gist options
  • Save ryanbriones/808938 to your computer and use it in GitHub Desktop.
Save ryanbriones/808938 to your computer and use it in GitHub Desktop.
some jQuery to cycle through web fonts
function setGlobalFont(fontName) {
console.log('setting font to ' + fontName);
document.body.style.fontFamily = fontName + " !important";
}
$(document).ready(function() {
$.fonts = [
"Arial", "Verdana", "Geneva", "Helvetica", "Helvetica Neue",
"Georgia", "Palatino", "Times New Roman", "Times",
"Courier New", "Courier"
]
$.currentFont = "Arial";
// setGlobalFont($.currentFont);
$(document).keyup(function(event) {
if(event.keyCode == 40) {
event.preventDefault();
var currentIndex = $.fonts.indexOf($.currentFont);
if(currentIndex == ($.fonts.length - 1))
currentIndex = -1;
$.currentFont = $.fonts[currentIndex + 1];
setGlobalFont($.currentFont);
}
if(event.keyCode == 38) {
event.preventDefault();
var currentIndex = $.fonts.indexOf($.currentFont);
if(currentIndex == 0)
currentIndex = $.fonts.length;
$.currentFont = $.fonts[currentIndex - 1];
setGlobalFont($.currentFont);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment