Skip to content

Instantly share code, notes, and snippets.

@adelbalso
Created May 8, 2013 16:36
Show Gist options
  • Save adelbalso/5541713 to your computer and use it in GitHub Desktop.
Save adelbalso/5541713 to your computer and use it in GitHub Desktop.
function getMargin(section) {
var viewPortHeight = $(window).height()
var sectionHeight = $(section).height()
, difference = (viewPortHeight - sectionHeight)
, margin = (difference > 0) ? difference / 2 : 0
// Max view height of 500 (divided by 2 is 250)
return Math.min(250, margin)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment