Skip to content

Instantly share code, notes, and snippets.

@hastebrot
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hastebrot/2ecb9a9a26505079bb64 to your computer and use it in GitHub Desktop.
Save hastebrot/2ecb9a9a26505079bb64 to your computer and use it in GitHub Desktop.
$(function() {
var atPosition = function($element, position) {
var top = $element[0] == window ? 0 : $element.position().top;
var height = $element.height();
if (position == "top") { return top; }
if (position == "bottom") { return top + height; }
throw "unknown position";
};
var alignAbsolutePosition = function($element, top, height) {
$element.css("position", "absolute");
$element.css("top", top);
$element.css("height", height);
};
$(window).resize(function() {
var $window = $(window);
var $header = $("#header");
var $content = $("#content");
var topAnchor = atPosition($header, "bottom");
var bottomAnchor = atPosition($window, "bottom");
alignAbsolutePosition($content, topAnchor, bottomAnchor - topAnchor);
});
$(window).trigger("resize");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment