Last active
December 16, 2015 07:09
-
-
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
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
//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