Last active
April 8, 2022 11:59
-
-
Save elliottmangham/f7a0941dd76d06e8c6beb2cc4062ac19 to your computer and use it in GitHub Desktop.
JS / Utilities / Accordions
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
function cAccordions( i, oComp ) { | |
var oComp = $( oComp ); | |
var oAccordions = $( '.c_accordion', oComp ); | |
/*************** | |
* Accordions | |
***************/ | |
$( '.accordion_head', oAccordions ).on( 'click', function() { | |
var oThisAccordion = $( this ).parent( '.c_accordion' ); | |
var oThisContent = oThisAccordion.find( '.accordion_value' ), | |
oSiblingAccordions = oThisAccordion.siblings( '.c_accordion' ); | |
if ( oThisAccordion.hasClass( 'is-open' ) ) { | |
/* Close accordion */ | |
oThisAccordion.removeClass( 'is-open' ); | |
oThisContent.slideUp( 400 ).animate( { | |
opacity: 0 | |
}, { | |
queue: false, | |
duration: 400 | |
} ); | |
} else { | |
/* Open accordion */ | |
oThisAccordion.addClass( 'is-open' ); | |
oThisContent.css( 'opacity', 0 ).slideDown( 400 ).animate( { | |
opacity: 1 | |
}, { | |
queue: false, | |
duration: 400 | |
} ); | |
/* Close siblings */ | |
oSiblingAccordions.removeClass( 'is-open' ).find( '.accordion-content' ).slideUp( 400 ).animate( { | |
opacity: 0 | |
}, { | |
queue: false, | |
duration: 400 | |
} ); | |
} | |
/* Update scroll */ | |
setTimeout( () => { | |
scroll.update(); | |
}, 400 ); | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment