Created
August 9, 2012 03:04
-
-
Save oomlaut/3300541 to your computer and use it in GitHub Desktop.
Basic Accordion UI Element
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
<dl class="accordion"> | |
<dt>Accordion Heading 1</dt> | |
<dd> | |
<p>Some content</p></dd> | |
<dt>Accordion Heading 2</dt> | |
<dd> | |
<p>Some more content</p></dd> | |
<dt>Accordion Heading 3</dt> | |
<dd> | |
<p>Some final content</p></dd> | |
</dl> |
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
if (typeof jQuery != "undefined") { | |
(function($) { | |
$('.accordion dt').each(function() { | |
$(this).on('click', function(){ | |
$(this).toggleClass('on').siblings('.on').removeClass('on').end() | |
.next('dd').slideToggle().siblings('dd').slideUp(); | |
}).next('dd').hide(); | |
}); | |
})(jQuery); | |
} |
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
.accordion { border:1px solid #ccc; } | |
.accordion dt { padding:.5em; background-color:#dadada; cursor:pointer; } | |
.accordion dt:hover { color:#666; } | |
.accordion .on { background-color:#eaeaea; cursor:default; } | |
.accordion dt, | |
.accordion .on:hover { color:#111; } | |
.accordion dd { padding-left:.5em; padding-right:.5em; } | |
/* NOTE: | |
Do not apply top/bottom padding or margin to the accordion content, | |
as its affects to the box model will cause the animation to be choppy. | |
Instead, apply vertical spacing to the content elements. | |
*/ | |
.accordion dd p { padding-top:.5em; padding-bottom:.5em; } | |
body{ padding:2em; } /* used only to pretty up the display panel */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment