Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Created January 5, 2015 09:57
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 glueckpress/85558d95f60232f46633 to your computer and use it in GitHub Desktop.
Save glueckpress/85558d95f60232f46633 to your computer and use it in GitHub Desktop.
Vertically align team member content to clicked ui tabs on Human Made’s team page (http://hmn.md/is/).
/**
* Vertically align team member content to clicked ui tabs.
*
* @link http://hmn.md/is/
*
*/
( function( $ ) {
$( '.ui-tabs-anchor', '.about-teamlist' ).on( 'click', function( e ) {
var $item = $( this );
var $list = $( '.about-teamlist' );
var $content = $( '.about-teammember[aria-hidden="false"]' );
var offsets = { // top offsets
'item' : $item.offset().top,
'list' : $list.offset().top
};
var halflings = { // halved heights
'item' : $item.innerHeight() / 2,
'content' : $content.innerHeight() / 2
};
// calcualte new top margin for content
if( offsets.item - offsets.list > halflings.content ) { // vertically align content to ui tab
var newPos = offsets.item - offsets.list + halflings.item - halflings.content;
} else { // upper end of list: do nothing
var newPos = 0;
}
// set new top margin for content
$content.css( { 'margin-top' : newPos + 'px' } );
// @todo Calculations should consider scroll positions and key events.
} );
} ) ( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment