Created
March 23, 2012 21:06
-
-
Save samuelcole/2175065 to your computer and use it in GitHub Desktop.
A little plugin for preloading background images (for spinners 'n stuff).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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