Last active
December 31, 2015 00:39
-
-
Save kikobr/7908820 to your computer and use it in GitHub Desktop.
Sanfona
This file contains 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
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'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
é necessårio que a sublista tenha height:0 e overflow:hidden,