Created
July 10, 2012 07:50
-
-
Save Mr2P/3081898 to your computer and use it in GitHub Desktop.
background size cover polyfill for IE (6, 7, 8)
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 ($) { | |
"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