To preload, why not grab the url from the css attribute using jQuery? Something like that:
var bg_url = jQuery("#DIV-THAT-NEEDS-PRELOADING").css('background-image'); // using regex to replace the " url( ... ) "... // apologies for my noobish regex skills... bg_url = str.replace(/ /g, '', bg_url); // whitespace... bg_url = str.replace(/url\(["']?/g, '', bg_url); // next, the 'url("'... bg_url = str.replace(/["']?\)/g, '', bg_url); // finally, the trailing '")'... // without regex, using substring if confident about no quotes / whitespace... bg_url = bg_url.substring(4, bg_url.length-1); // preloading... var img = new Image(); img.onload = function() { // do transitions here... }; img.src = bg_url;
Chris kempen
source share