Created
June 29, 2020 08:51
-
-
Save amityweb/8c32496cb4a837bb618f07a2ea6a46f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* HTML/PHP */ | |
<div class="accordion"> | |
<?php foreach($accordions AS $accordion) : ?> | |
<div class="accordion-row col sixcol"> | |
<a href="#" class="accordion-title"><?php echo $accordion['question'];?></a> | |
<div class="accordion-text"><?php echo $accordion['answer'];?></div> | |
</div> | |
<?php endforeach;?> | |
</div> | |
/* CSS */ | |
.accordion | |
{ | |
overflow: visible; | |
} | |
.accordion-row | |
{ | |
position: relative; | |
} | |
.accordion-title | |
{ | |
padding: 10px 0; | |
} | |
.accordion-text | |
{ | |
display: none; | |
} | |
/* JQuery */ | |
$(document).ready(function() | |
{ | |
if($('.accordion').length > 0) | |
{ | |
$(".accordion-title").click(function(e) | |
{ | |
e.preventDefault(); | |
$('.accordion-text').slideUp('fast'); | |
if( !$(this).hasClass('open') ) | |
{ | |
$(this).addClass('open').next('.accordion-text').slideDown('fast'); | |
} | |
else | |
{ | |
$('.accordion-title').removeClass('open'); | |
$('.accordion-text').slideUp('fast'); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment