Accordion

Accordion code snippet
Share:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Accordion HTML Structure

Struktur Akordion

Notes: Duplicate accordion item as your need

Accordion CSS

/*accordion*/
.accordion {
  width:100%;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
  overflow:hidden;	
}

.accordion_item {
  width:100%;
  background:color(1);
  color:white;
}

.accordion_icon {
	color:color(2);
}

.accordion_title {

	cursor: pointer;
	
	display: flex;
    flex-direction: row;
    
    justify-content: space-between;
	width:100%;
	-webkit-transition: all 0.4s ease;
	-o-transition: all 0.4s ease;
	transition: all 0.4s ease;
   font-weight:600;
	/*border-top:1px solid #00000010;
	border-bottom:1px solid #00000010;*/
}

.accordion_content {
	display: none;
	width:100%;
}

.open .accordion_title { 
	color: #fff;
	background:color(1);
	border-radius:4px 4px 0 0;
 
}

.open .accordion_icon {
	-webkit-transform: rotate(180deg);
	-ms-transform: rotate(180deg);
	-o-transform: rotate(180deg);
	transform: rotate(180deg);
}
.accordion_icon, .open .accordion_icon {
	-webkit-transition: all 0.4s ease;
	-o-transition: all 0.4s ease;
	transition: all 0.4s ease;
}

Notes: Modified CSS as your need

Accordion Javascript

  jQuery(function() {
	var Accordion = function(el, multiple) {
		this.el = el || {};
		this.multiple = multiple || false;

		// Variables privadas
		var links = this.el.find('.accordion_title');
		// Evento
		links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown)
	}

      Accordion.prototype.dropdown = function(e) {
          var $el = e.data.el;
              $this = jQuery(this),
              $next = $this.next();
  
          $next.slideToggle();
          $this.parent().toggleClass('open');
  
          if (!e.data.multiple) {
              $el.find('.accordion_content').not($next).slideUp().parent().removeClass('open');
          };
      }	
  
      var accordion = new Accordion(jQuery('.accordion'), false);
    });

// if you want to open first accordion, you can add open class in first accordion_item and set accordion_content display to block
// if you use repeater module, you can try this code
jQuery(window).on('load', function() {
  jQuery('.accordion_item:first-child').addClass('open');
  jQuery('.accordion_item:first-child .accordion_content').css("display","block");
});

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Article

Adding RSS Feed from Another WordPress Website
Flickity Slider Constant Autoplay
Snippet from: https://codepen.io/HiddeDeRidder/pen/aQNoEe
Fade-In Effect on Window Load
Javascript code for fade-in effect on window load
COMPLETE PACKAGE OF WEBSITE DESIGN & DEVELOPMENT
Digitalizer offers website design & development services for company profiles, online shops, event organizers, educational institutions or other fields. You don't need to think about domains, web hosting / servers, DNS, email, design, development, security and other technical issues. Just prepare your website content, we do the rest.
All website design & development packages include 1 year maintenance!
Free Consultation
Back to top
cross