Created
January 17, 2014 15:32
-
-
Save aronbudinszky/8475355 to your computer and use it in GitHub Desktop.
Background cover with javascript.
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
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