Created
February 3, 2011 02:39
-
-
Save ryanbriones/808938 to your computer and use it in GitHub Desktop.
some jQuery to cycle through web fonts
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
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