Skip to content

Instantly share code, notes, and snippets.

@Mr2P
Created July 10, 2012 07:50
Show Gist options
  • Save Mr2P/3081898 to your computer and use it in GitHub Desktop.
Save Mr2P/3081898 to your computer and use it in GitHub Desktop.
background size cover polyfill for IE (6, 7, 8)
!function ($) {
"use strict"; // jshint ;_;
var BGCover = function (element, options) {
this.$element = $(element);
this.options = options;
this.init();
}
BGCover.prototype = {
init: function () {
if ("backgroundSize" in document.body.style) {
return;
}
var that = this;
var img = $('<img />').attr('src', this.options.imageUrl);
img.css({
'min-height': '100%',
'min-width': '960px',
'width': '100%',
'height': 'auto',
'position': 'fixed',
'top': 0,
'left': 0,
'z-index': '-1'
});
this.$element.prepend(img);
}
}
$.fn.bgCover = function (option) {
return this.each(function () {
var $this = $(this),
options = $.extend({}, $.fn.bgCover.defaults, typeof option == 'object' && option);
$this.data('bgCover', (new BGCover(this, options)));
});
}
$.fn.bgCover.defaults = {
imageUrl: '/Templates/Netcat/Styles/images/bg-placeholder.jpg'
};
$.fn.bgCover.Constructor = BGCover;
$(function () {
$(document.body).bgCover();
});
} (window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment