Created
January 13, 2015 01:09
-
-
Save pospi/3af2659558a421e7e8b8 to your computer and use it in GitHub Desktop.
TweenLite slideToggle behaviour using scrollHeight attribute for height calculation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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