Bootstrap collapse

Bootstrap collapse plugin allows you to toggle content on your pages with a bit of JavaScript and some classes. A flexible plugin that utilizes a handful of classes for easy toggle behavior.


Basic examples

Click the buttons below to show and hide another element via class changes:

  1. .collapse hides content
  2. .collapsing is applied during transitions
  3. .collapse.show shows content

You can use a link with the href attribute, or a button.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.


<collapse :toggleTag="['a', 'button']" :togglers="2" :toggleClass="['btn btn-primary', 'btn-primary']" :toggleText="['Collapse link', 'Collapse button']">
  <h5 class="pt-3">Collapsing text</h5>
  <p class="pb-3">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</collapse>
            

Multiple targets

A <button> or <a> can show and hide multiple elements by referencing them with a JQuery selector in its href or data-target attribute. Multiple <button> or <a> can show and hide an element if they each reference it with their href or data-target attribute.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.

<template>
  <container>
    <btn color="primary" @click.native.prevent="collapse2 === true ? collapse2 = false : collapse2 = true">Toggle first element</btn>
    <btn color="primary" @click.native.prevent="collapse3 === true ? collapse3 = false : collapse3 = true">Toggle second element</btn>
    <btn color="primary" @click.native.prevent="[collapse2 === true ? collapse2 = false : collapse2 = true] && [collapse3 === true ? collapse3 = false : collapse3 = true]">Toggle both elements</btn>
    <row>
      <column sm="6">
        <transition @before-enter="beforeEnter" @enter="enter" @before-leave="beforeLeave">
          <card v-if="collapse2" class="collapse-item mt-2">
            <card-body>
              <h5 class="pt-2">Collapsing text</h5>
              <p class="pb-2">(...)</p>
            </card-body>
          </card>
        </transition>
      </column>
      <column sm="6">
        <transition @before-enter="beforeEnter" @enter="enter" @before-leave="beforeLeave">
          <card v-if="collapse3" class="collapse-item mt-2">
            <card-body>
              <h5 class="pt-2">Collapsing text</h5>
              <p class="pb-2">(...)</p>
            </card-body>
          </card>
        </transition>
      </column>
    </row>
  </container>
</template>

<script>
import { Collapse, Btn, Container, Column, Row, Card, CardBody } from 'mdbvue';

export default {
  name: 'CollapsePage',
  components: {
    Collapse,
    Btn,
    Container,
    Column,
    Row,
    Card,
    CardBody
  },
  data() {
    return {
      collapse1: false,
      collapse2: false,
      collapse3: false
    };
  },
  methods: {
    beforeEnter(el) {
      this.elHeight = el.scrollHeight;
    },
    enter(el) {
      el.style.height = this.elHeight+'px';
    },
    beforeLeave(el) {
      el.style.height = 0;
    }
  }
};
</script>
  
<style scoped>
  .collapse-item {
    overflow: hidden;
    height: 0;
    padding: 0;
    transition: height .5s;
  }
</style>
            

Accordion MDB Pro component

Using the card component, you can extend the default collapse behavior to create an accordion.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                
<template>
  <div class="mt-5">
    <container>
      <accordion>
        <card>
          <card-header>
            <a href="#" @click.prevent="active === 1 ? active = 0 : active = 1">
              <h5 class="mb-0">
                Collapsible Group Item #1 <fa icon="angle-down" :class="active === 1 ? 'rotate-icon' : ''"/>
              </h5>
            </a>
          </card-header>
          <transition @before-enter="beforeEnter" @enter="enter" @before-leave="beforeLeave">
            <card-body v-if="active === 1" class="collapse-item">
              <p class="p-2">
                (...)
              </p>
            </card-body>
          </transition>
        </card>
        <card>
          <card-header>
            <a href="#" @click.prevent="active === 2 ? active = 0 : active = 2">
              <h5 class="mb-0">
                Collapsible Group Item #2 <fa icon="angle-down" :class="active === 2 ? 'rotate-icon' : ''"/>
              </h5>
            </a>
          </card-header>
          <transition @before-enter="beforeEnter" @enter="enter" @before-leave="beforeLeave">
            <card-body v-if="active === 2" class="collapse-item">
              <p class="p-2">
                (...)
              </p>
            </card-body>
          </transition>
        </card>
        <card>
          <card-header>
            <a href="#" @click.prevent="active === 3 ? active = 0 : active = 3">
              <h5 class="mb-0">
                Collapsible Group Item #3 <fa icon="angle-down" :class="active === 3 ? 'rotate-icon' : ''"/>
              </h5>
            </a>
          </card-header>
          <transition @before-enter="beforeEnter" @enter="enter" @before-leave="beforeLeave">
            <card-body v-if="active === 3" class="collapse-item">
              <p class="p-2">
                (...)
              </p>
            </card-body>
          </transition>
        </card>
      </accordion>
    </container>
  </div>
</template>

<script>
import { Container, Accordion, Card, CardHeader, CardBody, Fa } from 'mdbvue';

export default {
  data() {
    return {
      active: 1,
      elHeight: 0
    };
  },
  name: 'AccordionPage',
  components: {
    Container,
    Accordion,
    Card,
    CardHeader,
    CardBody,
    Fa
  },
  methods: {
    beforeEnter(el) {
      this.elHeight = el.scrollHeight;
    },
    enter(el) {
      el.style.height = this.elHeight+'px';
    },
    beforeLeave(el) {
      el.style.height = 0;
    }
  }
};
</script>

<style scoped>
.collapse-item {
  overflow: hidden;
  height: 0;
  padding: 0;
  transition: height .5s;
}
</style>