I have a problem with jQuery and @font-face.
I need to work out the height of a <div>
, which works fine, but then there is a small delay for the fonts to load and as soon as they do, the @font-face fonts were actually bigger than the fallback fonts, so the height is smaller than it should be.
I have tried using Modernizr, but that is no use as it only detects if the browser is capable of @font-face, not whether the fonts have loaded yet or not.
The jQuery code is in $(document).ready, but I guess fonts don't delay that from firing. Any ideas anyone?
I have a problem with jQuery and @font-face.
I need to work out the height of a <div>
, which works fine, but then there is a small delay for the fonts to load and as soon as they do, the @font-face fonts were actually bigger than the fallback fonts, so the height is smaller than it should be.
I have tried using Modernizr, but that is no use as it only detects if the browser is capable of @font-face, not whether the fonts have loaded yet or not.
The jQuery code is in $(document).ready, but I guess fonts don't delay that from firing. Any ideas anyone?
Share Improve this question edited Jan 26, 2015 at 8:11 Shaun asked Jul 22, 2010 at 16:20 ShaunShaun 6426 silver badges19 bronze badges 2- 6 Have you tried $(window).load instead of document.ready? – Adam Commented Jul 22, 2010 at 16:25
- Thanks Adam, that was perfect. – Shaun Commented Jul 29, 2010 at 14:53
3 Answers
Reset to default 16The perfect solution was, as Adam pointed out, using $(window).load
instead of $(document).ready
$(window).load(function(){
$(".column").equalHeights();
});
The Google font api looks like it works as long as you load fonts from google, typekit or ascender. But if you are using something else (e.g. another font downloaded from fontsquirrel) you might want to try something like this to figure out the font being rendered. You may also want to check out this discussion on determining the font being used Changing Body Font-Size based on Font-Family with jQuery
You might want to check out the Google Font API (http://code.google.com/apis/webfonts/docs/webfont_loader.html). I believe it dynamically loads the font and fires off a number of events that you can act on (for resizing your 's).