Styling custom font web pages using @font-face requires the browser to first download the font file (just like it loads other assets, such as CSS, JavaScripts, etc.) before the actual execution occurs.
This indicates a problem with Chrome (v16.0.912.63) and Safari (v5.1.2) when jQuery .height() tries to calculate the height of its container. The calculated height until the font finishes loading. Consider the following (view: working example ):
h1 { font-family: MuseoSlab-500, "Helvetica Neue", Helvetica, Arial, sans-serif; } <div id="box"> <h1>This is my long header. What do you think? How about now?</h1> </div> $(function() { alert("The height of the above <div> = " + $('div#box').height()); });
However, Firefox (v8.0.1) is able to calculate the correct height, that is, after rendering the text using a non-standard font.
The question is whether there is a practical way to tell Chrome or, ideally, to browsers, to wait for the text to be displayed using the intended font before doing the calculations.
Using $(window).load() works, but that means waiting, for example. all images to complete the download; it slows down so much.
source share