Skip to content

Instantly share code, notes, and snippets.

@aronbudinszky
Created January 17, 2014 15:32
Show Gist options
  • Save aronbudinszky/8475355 to your computer and use it in GitHub Desktop.
Save aronbudinszky/8475355 to your computer and use it in GitHub Desktop.
Background cover with javascript.
var backgroundCover = function(){
var wh = $(window).height();
var ww = $(window).width();
var wa = ww / wh;
$('div.carousel div.element.article img').each(function(){
var $this = $(this);
var ar = $this.attr('width') / $this.attr('height');
if(wa < ar) $this.css({'height': wh, 'width': 'auto', 'position': 'fixed'});
else $this.css({'height': 'auto', 'width': ww, 'position': 'fixed'});
});
}
$(window).load(backgroundCover);
$(window).resize(backgroundCover);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment