Created
December 22, 2011 20:54
-
-
Save chrisvanpatten/1511820 to your computer and use it in GitHub Desktop.
jQuery Fullscreenr
This file contains hidden or 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
/** | |
* Fullscreenr - lightweight full screen background jquery plugin | |
* By Jan Schneiders | |
* www.nanotux.com | |
* | |
* Modifications by Chris Van Patten | |
* http://www.vanpattenmedia.com | |
* Version 1.5 | |
**/ | |
(function($){ | |
$.fn.fullscreenr = function(options) { | |
var defaults = { width: 1280, height: 1024 }; | |
var options = $.extend({}, defaults, options); | |
return this.each(function () { | |
$(this).fullscreenrResizer(options); | |
}) | |
} | |
$.fn.fullscreenrResizer = function(options) { | |
// Set bg size | |
var ratio = options.height / options.width; | |
// Get browser window size | |
var browserwidth = $(window).width() + 80; | |
var browserheight = $(window).height(); | |
// Scale the image | |
if ((browserheight/browserwidth) > ratio){ | |
$(this).height(browserheight); | |
$(this).width(browserheight / ratio); | |
} else { | |
$(this).width(browserwidth); | |
$(this).height(browserwidth * ratio); | |
} | |
// Center the image | |
// $(this).css('left', (browserwidth - $(this).width())/2); | |
// $(this).css('top', (browserheight - $(this).height())/2); | |
return this; | |
} | |
})( jQuery ); |
This file contains hidden or 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
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>jQuery Fullscreenr Sample</title> | |
<script type="text/javascript" src="jquery.fullscreenr.js"></script> | |
<script type="text/javascript"> | |
$('#imageid').fullscreenr({width: 1229, height: 768}); | |
</script> | |
</head> | |
<body> | |
<header> | |
<h1>jQuery Fullscreenr Sample</h1> | |
</header> | |
<section> | |
<img src="images/image.jpg" alt="Just a test" id="imageid"> | |
</section> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great code Chris. I would like to use this code, but I was wondering how I can implement a parallax effect. I like to hear from you. Casper