Skip to content

Instantly share code, notes, and snippets.

@ethanclevenger91
Last active August 29, 2015 14:09
Show Gist options
  • Save ethanclevenger91/df95053fadf91f351772 to your computer and use it in GitHub Desktop.
Save ethanclevenger91/df95053fadf91f351772 to your computer and use it in GitHub Desktop.
Load webfonts asynchronously. A must if you're doing any kind of slabText. See https://github.com/typekit/webfontloader for all supported libraries
jQuery(document).ready(function($) {
//set up google fonts to load asynchronously with a callback on load
WebFontConfig = {
google: {
families:['Lato:400,700,900,400italic,900italic', 'Oswald'] //the fonts you need
},
typekit: {
id: 'xxxxxx' //supports typekit as well as others
},
active: function(familyName, fvd) { //callback when finished
//resize-justify hero text in header
$('.header .hero-text').slabText(); //slabtext will now have the right font size
//hide page initially, then fade in to avoid ugly font-popping
$('body').addClass('loaded');
new WOW().init(); //any other visual effects should probably wait until the page shows up, so they go here
}
};
//insert webfont script with above config
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment