Skip to content

Instantly share code, notes, and snippets.

@Werninator
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Werninator/997b69702b2293ed25da to your computer and use it in GitHub Desktop.
Save Werninator/997b69702b2293ed25da to your computer and use it in GitHub Desktop.
Accordion Script mit jQuery
(function($) {
$.fn.ffAccordion = function(options) {
if (typeof options == 'undefined')
options = {};
options = {
childSelector: options.childSelector || 'li',
subMenuSelector: options.subMenuSelector || 'ul',
trigger: options.trigger || 'hover',
animationSpeed: options.animationSpeed || 250,
}
return this.each(function() {
var that = $(this);
that.children(options.childSelector).each(function() {
$(this).children(options.subMenuSelector).each(function() {
$(this).attr('data-height-before', $(this).height());
$(this).css({
'height': '0px',
'overflow': 'hidden'
});
});
$(this).on(options.trigger, function() {
$(this).children(options.subMenuSelector).each(function() {
if ($(this).height() != 0)
return;
that.children(options.childSelector).each(function() {
$(this).children(options.subMenuSelector).each(function() {
$(this).clearQueue().animate({
'height': '0px',
}, options.animationSpeed);
});
});
$(this).clearQueue().animate({
'height': $(this).attr('data-height-before') + 'px'
}, options.animationSpeed);
});
});
});
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment