Created
November 9, 2017 00:37
-
-
Save dehamzah/83a70e56b88f0bdb53db7b24114da242 to your computer and use it in GitHub Desktop.
accordion
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
<script> | |
$('.js-accordion__toggle').click(function(e) { | |
e.preventDefault(); | |
var $this = $(this); | |
if ($this.next().hasClass('show')) { | |
$this.removeClass('active'); | |
$this.next().removeClass('show'); | |
$this.next().slideUp(350); | |
} else { | |
$this.parent().parent().find('li .c-accordion__title').removeClass('active'); | |
$this.parent().parent().find('li .c-accordion__content').removeClass('show'); | |
$this.parent().parent().find('li .c-accordion__content').slideUp(350); | |
$this.toggleClass('active'); | |
$this.next().toggleClass('show'); | |
$this.next().slideToggle(350); | |
} | |
}); | |
</script> |
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
<ul class="c-accordion"> | |
<li> | |
<a href="javascript:void(0)" class="c-accordion__title js-accordion__toggle"> | |
Item 1 | |
</a> | |
<div class="c-accordion__content"> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime assumenda voluptatem alias impedit facere, quas eius natus perspiciatis et, expedita sint officia harum magni iusto porro quam architecto. Perferendis, autem.</p> | |
</div> | |
</li> | |
<li> | |
<a href="javascript:void(0)" class="c-accordion__title js-accordion__toggle"> | |
Item 1 | |
</a> | |
<div class="c-accordion__content"> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime assumenda voluptatem alias impedit facere, quas eius natus perspiciatis et, expedita sint officia harum magni iusto porro quam architecto. Perferendis, autem.</p> | |
</div> | |
</li> | |
</ul> |
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
.c-accordion { | |
list-style: none; | |
padding: 0; | |
margin: 0; | |
li { | |
padding: 15px 0 15px 20px; | |
} | |
&__title { | |
display: block; | |
padding: 10px 0; | |
position: relative; | |
font-weight: 700; | |
color: $c-blue-1; | |
&:hover, | |
&:focus { | |
text-decoration: none; | |
} | |
&:before { | |
content: '\f0da'; | |
font-family: 'FontAwesome'; | |
display: inline-block; | |
position: absolute; | |
left: -20px; | |
top: 10px; | |
transition: transform 0.5s ease; | |
} | |
&.active { | |
&:before { | |
transform: rotate(90deg); | |
} | |
} | |
} | |
&__content { | |
overflow: hidden; | |
display: none; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment