Created
March 27, 2014 19:21
-
-
Save elzii/9815939 to your computer and use it in GitHub Desktop.
Chrome "Invisible Font" fix
This file contains hidden or 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 ($) { | |
// user-agent && user-agent helper methods | |
var ua = navigator.userAgent; | |
var regex_apple_webkit = new RegExp(/AppleWebKit\/([\d.]+)/); | |
var result_apple_webkit_regex = regex_apple_webkit.exec(ua); | |
var apple_webkit_version = (result_apple_webkit_regex === null ? null : parseFloat(regex_apple_webkit.exec(ua)[1])); | |
// global variables | |
var GLOBALS = { | |
// debug toggles | |
debug : false, | |
debug_skrollr : false, | |
// user-agents | |
user_agent : { | |
iOS : (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false), | |
iphone : (navigator.userAgent.match(/(iPhone|iPod)/g) ? true : false), | |
ipad : (navigator.userAgent.match(/(iPad)/g) ? true : false), | |
android : (navigator.userAgent.match(/(Android)/g) ? true : false), | |
mobile : ((/Mobile|iPhone|iPod|BlackBerry|Windows Phone/i).test(navigator.userAgent || navigator.vendor || window.opera) ? true : false), | |
mobile_all : ((/Mobile|Android|iPhone|iPod|BlackBerry|Windows Phone/i).test(navigator.userAgent || navigator.vendor || window.opera) ? true : false), | |
}, | |
browser : { | |
desktop_chrome : (window.chrome ? true : false), | |
iphone_chrome : ((navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/) && navigator.userAgent.match('CriOS')) ? true : false), | |
iphone_safari : ((navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/) && !navigator.userAgent.match('CriOS')) ? true : false), | |
android_native : (ua.indexOf('Android') > -1 && ua.indexOf('Mozilla/5.0') > -1 && ua.indexOf('AppleWebKit') > -1 && ua.indexOf('Chrome') <= -1), | |
android_chrome : (ua.indexOf('Android') > -1 && ua.indexOf('Mozilla/5.0') > -1 && ua.indexOf('AppleWebKit') > -1 && ua.indexOf('Chrome') > -1), | |
android_samsung : (ua.indexOf('Android') > -1 && ua.indexOf('Mozilla/5.0') > -1 && ua.indexOf('AppleWebKit') > -1 && ua.indexOf('Chrome') > -1 && ua.indexOf('SCH') > -1) | |
} | |
} | |
// DOCUMENT READY | |
//////////////////////////////////////// | |
$(document).ready(function(){ | |
// invisible font fix for chrome | |
if ( GLOBALS.browser.desktop_chrome ) { | |
// Method 1 - Reset <body> width in a setTimeout | |
var chrome_fix_1 = function( duration ) { | |
setTimeout(function() { | |
$('body').width($('body').width()+1).width('auto'); | |
}, duration); | |
} | |
// Invoke Method 1 | |
// chrome_fix_1(500); | |
// Method 2 - Redeclare <body> offset onload | |
var chrome_fix_2 = function() { | |
var orig_body_offset = $('body').offset(); | |
$('body').offset(orig_body_offset); | |
} | |
// Invoke Method 2 | |
chrome_fix_2(); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment