Last active
August 29, 2015 14:13
-
-
Save Werninator/997b69702b2293ed25da to your computer and use it in GitHub Desktop.
Accordion Script mit jQuery
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
(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