Skip to content

Instantly share code, notes, and snippets.

@tcmacdonald
Created January 3, 2012 16:06
Show Gist options
  • Save tcmacdonald/1555514 to your computer and use it in GitHub Desktop.
Save tcmacdonald/1555514 to your computer and use it in GitHub Desktop.
Vertically Align Children
(($) ->
$.fn.valign = (max_width, max_height) ->
@each (i) ->
$.each $(this).children(), (j,el) ->
img = $(el).children()[0]
ph = Math.floor((max_width - $(img).width()) / 2)
pv = Math.floor((max_height - $(img).height()) / 2)
div = $('<div></div>').css('padding',"#{pv}px #{ph}px")
$(img).wrap(div)
) jQuery
$(window).load ->
$('#assets .slides').valign(500,440)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment