Skip to content

Instantly share code, notes, and snippets.

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 arturparkhisenko/cfe15f3b10cf106f1ad1 to your computer and use it in GitHub Desktop.
Save arturparkhisenko/cfe15f3b10cf106f1ad1 to your computer and use it in GitHub Desktop.
Responsive images feature detection
(function (window) {
document.addEventListener("DOMContentLoaded", function (e) {
var supports = {
srcset: false,
currentSrc: false,
sizes: false,
picture: false
};
var img = new Image();
if ("srcset" in img) {
supports.srcset = true;
}
if ("currentSrc" in img) {
supports.currentSrc = true;
}
if ("sizes" in img) {
supports.sizes = true;
}
if ("HTMLPictureElement" in window) {
supports.picture = true;
}
console.log('Picture support: ' + supports.picture);
console.log('sizes support: ' + supports.sizes);
console.log('srcset support: ' + supports.srcset);
console.log('currentSrc support: ' + supports.currentSrc);
});
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment