Always being annoyed by the boring accordion of Bootstrap, I created two by using jQuery.
Simple but Useful.
<p class="title"><b>No Boostrap</b> | jQueryAnimated Accordions</p> | |
<div class="container"> | |
<div id="accordion-1"> | |
<div class="head"> | |
<h2>1. Simple Accordion</h2> | |
<i class="fas fa-angle-down arrow"></i> | |
</div> | |
<div class="content"> | |
<p>An accordion is used to show and hide content. It can be usually found in Q & A section.</p> | |
</div> | |
</div> | |
<br> | |
<div id="accordion-2"> | |
<div class="head"> | |
<h2>2. Chatbox-like Accordion</h2> | |
<i class="arrow"></i> | |
</div> | |
<div class="content"> | |
<p>An accordion is used to show and hide content. It can be usually found in Q & A section.</p> | |
</div> | |
</div> | |
</div> | |
<p class="remarks">Created By <a href="https://codepen.io/nikoso">Niko</a></p> |
$('.head').click(function(){ | |
$(this).toggleClass('active'); | |
$(this).parent().find('.arrow').toggleClass('arrow-animate'); | |
$(this).parent().find('.content').slideToggle(280); | |
}); | |
// icon from Font Awesome was used in accordion-1 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> |
@import url(https://fonts.googleapis.com/css?family=Lato:300,900); | |
body{ | |
font-family: Lato; | |
background: linear-gradient(5deg, rgba(155,203,201,1) 0%, rgba(133,105,159,1) 60%); | |
height: 800px; | |
} | |
p.title{ | |
text-align: center; | |
font-size: 45px; | |
color: #efdeff; | |
} | |
b{ | |
color: #FFFFFF; | |
font-size: 55px; | |
} | |
p.remarks, a{ | |
text-align: center; | |
margin-top: 100px; | |
color: #FFFFFF; | |
} | |
.container{ | |
width: 100%; | |
max-width: 700px; | |
min-width: 300px; | |
margin: 0 auto; | |
padding: 0 5vh; | |
} | |
/* accordion-1 */ | |
#accordion-1{ | |
position: relative; | |
box-shadow: 0px 1px 7px #DBDBDB; | |
} | |
#accordion-1 .head{ | |
background-color: #FFFFFF; | |
color: #563e6e; | |
padding: 20px 30px; | |
cursor: pointer; | |
transition: 0.2s ease; | |
display: flex; | |
justify-content: space-between; | |
align-items: center; | |
} | |
#accordion-1 .arrow{ | |
color: #563e6e; | |
font-size: 60px; | |
transition: 0.25s ease; | |
opacity: 0.3; | |
transform: rotate(-90deg); | |
} | |
#accordion-1 .head:hover .arrow{ | |
opacity: 1; | |
} | |
#accordion-1 .head:hover, #accordion-1 .active{ | |
background-color: #FFE77AFF; | |
} | |
#accordion-1 .arrow-animate{ | |
transform: rotate(0deg); | |
opacity: 1; | |
} | |
#accordion-1 .content{ | |
background-color: #FFFFFF; | |
display: none; | |
padding: 20px 30px; | |
color: #333333; | |
} | |
/* accordion-2 */ | |
#accordion-2{ | |
position: relative; | |
box-shadow: 0 1px 7px #DBDBDB; | |
} | |
#accordion-2 .head{ | |
background-color: #FFFFFF; | |
color: #563e6e; | |
padding: 20px 30px; | |
cursor: pointer; | |
transition: 0.25s; | |
} | |
#accordion-2 .arrow{ | |
content:''; | |
position: absolute; | |
right: 0; | |
right: 30px; | |
top: 65px; | |
opacity: 1; | |
border-left: 35px solid transparent; | |
border-right: 35px solid transparent; | |
border-top: 40px solid #FFFFFF; | |
transition: 0.3s ease; | |
z-index: 2; | |
} | |
#accordion-2 .head:hover .arrow, #accordion-2 .arrow-animate{ | |
border-top: 40px solid #FFE77AFF; | |
transform: translateY(40px); | |
} | |
#accordion-2 .content{ | |
background-color: #FFFFFF; | |
display: none; | |
padding: 30px; | |
color: #333333; | |
} | |
#accordion-2 .head:hover, #accordion-2 .active{ | |
background-color: #FFE77AFF; | |
} |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet" /> |