Skip to content

Instantly share code, notes, and snippets.

@aFarkas aFarkas/sizes-detection.js
Last active Oct 19, 2015

Embed
What would you like to do?
(function(){
'use strict';
var width2 = 'data:image/gif;base64,R0lGODlhAgABAPAAAP///wAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==';
var width1 = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
var img = document.createElement('img');
var test = function(){
var width = img.width;
if(width == 2){
alert('your browser support sizes');
} else {
alert('your browser does not support sizes');
}
};
img.onload = test;
img.onerror = test;
img.setAttribute('sizes', '9px');
img.srcset = width1 + ' 1w,' + width2 + ' 8w';
img.src = width1;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.