How to make custom Accordian through jQuery. Copy the code and paste the code and save the file in HTML format and see the preview.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Accordian Through JQuery</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$(".cont").css('display','block');
$(".heading-accordian").click(function(){
if(($(this).parent().find('.maincontent').css('display') != 'block')){
$(".maincontent").removeClass('cont');
$(".maincontent").slideUp();
$(".roundarrow a").removeClass("active")
$(this).parent().find('.maincontent').slideDown();
$(this).children().children().addClass("active")
}
})
});
</script>
<style>
body{padding:0; margin:0; font-family: 'Open Sans', sans-serif;}
.container{width:1170px; margin:0 auto;}
.main{margin:0 auto; width:755px; float:left;}
.main-outer{width:755px; border:1px solid #d1d1d1; box-sizing:border-box; float:left; border-radius:4px; margin-bottom:10px;}
.heading-accordian{display:inline-block; width:100%; padding:15px 0; background-color:#e4e4e4; cursor:pointer}
.heading-accordian h2{font-size:22px; line-height:26px; color:#333; display:block; text-align:center; margin:0;}
.maincontent{display:none; width:100%; padding:1%; box-sizing:border-box;}
.mainheading{display:block; border-bottom:1px solid #dbdbdb;}
.maindetails{display:block;}
.roundarrow{float:right; width:20px; height:20px; background-color:#000; border-radius:20px; text-align:center; margin-right:20px;}
.roundarrow a {border: solid #fff; border-width: 0 3px 3px 0; display: inline-block; padding: 3px;}
.up {transform: rotate(-135deg);-webkit-transform: rotate(-135deg);}
.active {transform: rotate(45deg);-webkit-transform: rotate(45deg); position:relative; top:-3px;}
.alianceright{float:right; width:370px;}
@media screen and (max-width:767px){
.main,.main-outer{width:100%;}
.heading-accordian h2{font-size:18px;}
}
</style>
</head>
<body>
<div class="container">
<div class="main">
<div class="main-outer">
<div class="heading-accordian">
<div class="roundarrow"> <a href="#" class="up active"></a> </div>
<h2>Heading text goes here</h2>
</div>
<div class="maincontent cont">
<div class="mainheading">
</div>
<div class="maindetails">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
<div class="main-outer">
<div class="heading-accordian">
<div class="roundarrow"> <a href="#" class="up"></a> </div>
<h2>Heading text goes here</h2>
</div>
<div class="maincontent">
<div class="mainheading">
</div>
<div class="maindetails">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
<div class="main-outer">
<div class="heading-accordian">
<div class="roundarrow"> <a href="#" class="up"></a> </div>
<h2>Heading text goes here</h2>
</div>
<div class="maincontent">
<div class="mainheading">
</div>
<div class="maindetails">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Excellent post, thanks for this. I gathered lots of information from this and I am happy about it. Do share more updates.
ReplyDeleteAngularJS Training in Chennai
AngularJS Training institute in Chennai
Angular 7 Training in Chennai
ccna Training in Chennai
ReactJS Training in Chennai
PHP Training in Chennai
Tally course in Chennai
ui ux design course in Chennai
AngularJS Training in Anna Nagar