Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions jquery.fullscreenBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,41 @@
};

function fillBg(selector, parentobj) {
var windowHeight = $(window).height();
var windowWidth = $(window).width();

$(selector, parentobj).each(function () {
var imgHeight = $(this).attr("height");
var imgWidth = $(this).attr("width");

var newWidth = windowWidth;
var newHeight = (windowWidth / imgWidth) * imgHeight;
var topMargin = ((newHeight - windowHeight) / 2) * -1;
var leftMargin = 0;

if (newHeight < windowHeight) {
var newWidth = (windowHeight / imgHeight) * imgWidth;
var newHeight = windowHeight;
var topMargin = 0;
var leftMargin = ((newWidth - windowWidth) / 2) * -1;
}

$(this).css({
height: newHeight + "px",
width: newWidth + "px",
marginLeft: leftMargin + "px",
marginTop: topMargin + "px",
display: "block"
});
});
}
})(jQuery);
var windowHeight = $(window).height();
var windowWidth = $(window).width();

var img = new Image();
img.src = ($(selector).attr ? $(selector).attr("src") : false) || $(selector).src;
$(img).load(function () {

var imgWidth = this.width;
var imgHeight = this.height;

$(selector, parentobj).each(function () {

var newWidth = windowWidth;
var newHeight = (windowWidth / imgWidth) * imgHeight;
var topMargin = ((newHeight - windowHeight) / 2) * -1;
var leftMargin = 0;

if (newHeight < windowHeight) {
var newWidth = (windowHeight / imgHeight) * imgWidth;
var newHeight = windowHeight;
var topMargin = 0;
var leftMargin = ((newWidth - windowWidth) / 2) * -1;
}

$(this).css({
height: newHeight + "px",
width: newWidth + "px",
marginLeft: leftMargin + "px",
marginTop: topMargin + "px",
display: "block"
});
});
});

}

})(jQuery);