Skip to content

Instantly share code, notes, and snippets.

@pospi
Created January 13, 2015 01:09
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 pospi/3af2659558a421e7e8b8 to your computer and use it in GitHub Desktop.
Save pospi/3af2659558a421e7e8b8 to your computer and use it in GitHub Desktop.
TweenLite slideToggle behaviour using scrollHeight attribute for height calculation
/**
* Prerequisites:
* element must be block-level & visible
* element must have height: 0
* element must have overflow: hidden
*
* Returns true if the element was shown, false if it was hidden
*/
function slideToggle(ul)
{
if (ul.hasClass('active')) {
TweenLite.to(ul[0], 0.3, { height: 0, onComplete: function() {
ul.removeClass('active').css('height', '');
}});
return false;
} else {
TweenLite.to(ul[0], 0.3, { height: ul.prop('scrollHeight'), onComplete: function() {
ul.addClass('active');
}});
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment