Skip to content

Instantly share code, notes, and snippets.

View alxdxn's full-sized avatar

Alex Dixon alxdxn

View GitHub Profile
@silenzium
silenzium / objectfit-fallback.js
Last active November 4, 2019 04:36
This is a simple fallback for the object-fit property on responsive images inside picture elements (with srcset and media-query sources). It hides the img on browsers that don't support object-fit and sets the current used image as a background-image with background-size:cover.
$(function() {
'use strict';
// the css selector for the container that the image should be attached to as a background-image
var imgContainer = '.cover-img picture';
function getCurrentSrc(element, cb)
{
var getSrc;
if (!window.HTMLPictureElement) {