Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery later than window load

I am using Cufon.replace to font replace some text on the site. Currently in IE8 standards mode when this is run outside a $(document).ready it is only happening ~50% of the time the rest of the time the DOM changes have occurred (viewing with IE8 built in dev toolbar) but no text is displayed.

Disabling the replace, and applying it manually through the console updates all the text correctly. Wrapping it in $(document).ready stops it from ever occurring - no DOM modifications (as far as I can tell from dev toolbar). However I cannot reapply manually from the console - so it may be lying to me.

Wrapping it in $(window).load seems to have the same effect as $(document).ready

Please note this only effects ie8 "Standards mode". It works fine in Firefox and IE7.

Any thoughts?

like image 426
tgandrews Avatar asked Nov 14 '22 07:11

tgandrews


1 Answers

I've experienced this before... I would wrap it in anonymous function and you can also use a simple setTimeout to delay it as well (may not be needed).

(function( $ ){ 
   // Your Cufon.replace()
   Cufon.replace('h1', { fontFamily: 'stack-overflow', hover: true });
   Cufon.now();

   // OPTIONAL - Delay by 150ms (you can experiment with this value)
   setTimeout(function(){ Cufon.refresh(); }, 150); 

})( jQuery );
like image 149
Timothy Perez Avatar answered Dec 19 '22 06:12

Timothy Perez