Last active
September 4, 2016 08:09
-
-
Save gregwhitworth/439e811cbb7493cf56da to your computer and use it in GitHub Desktop.
Responsive images feature detection
This file contains 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
(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
Would you be so kind to explain me why DOMContentLoaded event is necessary? If you run these checks before DOMContentLoaded, you will get different results?