Skip to content

Instantly share code, notes, and snippets.

@kikobr
Last active December 31, 2015 00:39
Show Gist options
  • Save kikobr/7908820 to your computer and use it in GitHub Desktop.
Save kikobr/7908820 to your computer and use it in GitHub Desktop.
Sanfona
var sanfona_speed = 200;
$(document).on('click', '[name=sanfona],[data-name=sanfona]', function(e){
e.preventDefault();
item_parent = $(this).parent();
item_content = $(this).siblings('[data-sanfona]') ? $(this).siblings('[data-sanfona]') : $(this).find('[data-sanfona]');
if(item_content && item_content.outerHeight() == 0){
height = item_content[0].scrollHeight;
// Terminada a animação, seta o height:auto para que as sublistas não sejam escondidas pela altura definida da possível sanfona pai.
item_content.animate({ height: height }, sanfona_speed, function(){
item_content.css('height', 'auto');
});
item_parent.toggleClass('active');
} else {
item_content.animate({ height: 0 }, sanfona_speed);
item_parent.toggleClass('active');
}
});
@kikobr
Copy link
Author

kikobr commented Mar 18, 2014

é necessårio que a sublista tenha height:0 e overflow:hidden,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment