Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery.fn.resizeWithWindow = function(options) {
- var settings = $.extend($.fn.resizeWithWindow.defaults, options),
- element = $(this);
- adjustSize(element);
- $(window).resize(function() {
- adjustSize(element);
- });
- function adjustSize(targets) {
- return targets.each(function() {
- var target = {
- height: $(this).height(),
- width: $(this).width()
- },
- browser = {
- height: $(window).height(),
- width: $(window).width()
- },
- ratio = {
- height: target.height / browser.height,
- width: target.width / browser.width
- };
- if (ratio.height > ratio.width) {
- $(this).css({
- 'width': 'auto',
- 'height': '100%'
- });
- settings.container
- .height(browser.height)
- .width($(this).width() + settings.offset_width);
- } else {
- settings.container
- .css('width', 'auto')
- .height($(this).height());
- $(this)
- .css({
- 'width': '100%',
- 'height': 'auto'
- });
- }
- return false;
- });
- }
- };
- jQuery.fn.resizeWithWindow.defaults = {
- container: $(this).parent(),
- offset_width: 0
- };
Add Comment
Please, Sign In to add comment