Created
May 20, 2014 19:05
-
-
Save victorono/7ed938038d2026101032 to your computer and use it in GitHub Desktop.
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
| jQuery.preloadImagesCSS = function() { | |
| var allImgs = [], | |
| k = 0, | |
| sheets = document.styleSheets; | |
| for (var i = 0; i<sheets .length; i++) { | |
| var cssPile = '', | |
| csshref = (sheets[i].href) ? sheets[i].href : 'window.location.href'; | |
| if (document.styleSheets[i].cssRules) { | |
| var thisSheetRules = document.styleSheets[i].cssRules; | |
| for (var j = 0; j<thisSheetRules.length; j++) { | |
| cssPile+= thisSheetRules[j].cssText; | |
| } | |
| } else { | |
| cssPile += document.styleSheets[i].cssText; | |
| } | |
| var imgUrls = cssPile.match(/[^\(]+\.(gif|jpg|jpeg|png)/g); | |
| if (imgUrls !== null && imgUrls.length > 0 && imgUrls !== '') { | |
| var images = jQuery.makeArray(imgUrls); | |
| jQuery(images).each(function(index, image){ | |
| allImgs[k] = new Image(); | |
| allImgs[k].src = image; | |
| k++; | |
| }); | |
| } | |
| } | |
| return allImgs; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment