I calculate the padding of an element and add it on resize. Now, I would like to add it also on page load. How can I do that?
$(window).resize(function () {
var widthWindow = $(window).width();
var widthContainer = $("#container").width();
var calculatePadding = (widthWindow - widthContainer) / 2;
$("#container").css({
"padding-top":calculatePadding,
"padding-bottom":calculatePadding
});
}).resize();
You could do it this way:
In Javascript:
(OR) the jQuery way