Skip to content

Instantly share code, notes, and snippets.

@samuelcole
Created March 23, 2012 21:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelcole/2175065 to your computer and use it in GitHub Desktop.
Save samuelcole/2175065 to your computer and use it in GitHub Desktop.
A little plugin for preloading background images (for spinners 'n stuff).
(function ($) {
function background_image_url($object) {
var string = $object.css('backgroundImage'),
url_regex = /[("]([^()"]+)[")]/;
return url_regex.exec(string)[1];
}
$.fn.preload_background_image = function () {
return $(this).each(function () {
(new Image()).src = background_image_url($(this));
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment