Skip to content

Instantly share code, notes, and snippets.

@aFarkas
Last active October 19, 2015 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aFarkas/2c4531393f9b1d18243c to your computer and use it in GitHub Desktop.
Save aFarkas/2c4531393f9b1d18243c to your computer and use it in GitHub Desktop.
(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