Created
June 15, 2010 18:08
-
-
Save falsefalse/439444 to your computer and use it in GitHub Desktop.
afair, this prints dimensions for all background images on the page
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
console.clear && console.clear(); | |
var images = []; | |
var elements = document.querySelectorAll('#global div'); | |
for (var i = 0, l = elements.length; i < l; i++) { | |
var element = elements[i]; | |
var bgImg = document.defaultView.getComputedStyle(element, null).getPropertyValue('background-image'); | |
if (bgImg == 'none') { | |
continue; | |
} | |
var match = bgImg.match(/url\((.+)\)/); | |
var image = { | |
url : match[1].replace(/\"/g, ''), | |
source : element | |
}; | |
var index = images.push(image) - 1; | |
var el = new Image(); | |
el.src = image.url; | |
el.onload = (function(images, index) { | |
return function(event) { | |
images[index].d = [this.width, this.height].join('×'); | |
if (images.length - 1 == index) { | |
for (var k = 0; k < images.length; k++) { | |
var image = images[k]; | |
var slice = image.url.match(/^.+\/(.+)\./)[1]; | |
console[(!image.d) ? 'group' : 'groupCollapsed'](image.url); | |
console.log(slice); | |
for (var prop in image) { | |
(prop != 'url') && console.log(image[prop]); | |
} | |
console.groupEnd(image.url); | |
} | |
} | |
} | |
})(images, index); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment