Skip to content

Instantly share code, notes, and snippets.

@komplexb
Last active December 16, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komplexb/5397028 to your computer and use it in GitHub Desktop.
Save komplexb/5397028 to your computer and use it in GitHub Desktop.
a bit like an accordion, except it doesn't collapse the other sections when you open one
//default style
.js-collapsibleHeader {
cursor: pointer;
}
//style when closed
.collapsibleHeader.closedContent {
}
//if the header style is for closed, then the associated body should be hidden
.js-collapsibleHeader.closedContent + .js-collapsibleContent {
display: none;
}
-------------------
<div class='closedContent js-collapsibleHeader'>
View Selected Products
</div>
<div class='js-collapsibleContent'>
content
</div>
<div class='js-collapsibleHeader'>
View Selected Products
</div>
<div class='js-collapsibleContent'>
content
</div>
--------------------
function toggleSection(headerSelector, bodySelector, speed)
{
$(headerSelector).click(function() {
var displayStateBefore = $(this).next(bodySelector).css('display');
$(this).next(bodySelector).slideToggle(speed);
var displayStateAfter = $(this).next(bodySelector).css('display');
if (displayStateBefore=='none' && displayStateAfter=='block') //section open; reflect correct styling
{
$(this).removeClass('closedContent');
}
else if (displayStateBefore=='block' && displayStateAfter=='block') //section closed; reflect correct styling
{
$(this).addClass('closedContent');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment