(function($) { var title, content, icon; function onDocumentReady() { title = $(".accordion__title"); content = $(".accordion__content"); icon = title.find(".toggle"); title.on("click", onAccordionToggleClick); //cache the vertical centering on document ready icon.velocity({translateY: "-50%"}, 10); } function onAccordionToggleClick(e) { var clicked = $(e.currentTarget), easingValue = clicked.data("easing"), sibling = title.not(clicked); if (clicked.next(content).is(":visible")) { clicked.next(content) .velocity("stop") .velocity("slideUp", {duration: 600, easing: easingValue}); clicked.find(icon) .velocity({rotateX: [0, 180]}, 600, easingValue); } else { if (sibling.next(content).is(":visible")) { clicked.next(content) .velocity("stop") .velocity("slideDown", { delay: 600, duration: 600, easing: easingValue}); clicked.find(icon) .velocity("stop") .velocity({rotateX: [180, 0]}, {delay:600, duration: 600, easing: easingValue}); sibling.next(content) .velocity("stop") .velocity("slideUp", {duration: 600, easing: easingValue}); sibling.find(icon) .velocity("stop") .velocity({rotateX: [0, 180]}, 600, easingValue); } else { clicked.next(content) .velocity("stop") .velocity("slideDown", {duration: 600, easing: easingValue}); clicked.find(icon) .velocity("stop") .velocity({rotateX: [180, 0]}, 600, easingValue); } } } $(onDocumentReady); })(jQuery);