Skip to content

Instantly share code, notes, and snippets.

@frontend-coder
Created August 12, 2019 06:11

Revisions

  1. frontend-coder created this gist Aug 12, 2019.
    18 changes: 18 additions & 0 deletions Simple Jquery Accordion
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <div>
    <div class="acc-btn">Button 1</div>
    <div class="acc-content">
    Content 1
    </div>
    </div>
    <div>
    <div class="acc-btn">Button 2</div>
    <div class="acc-content show">
    Content 2
    </div>
    </div>
    <div>
    <div class="acc-btn">Button 3</div>
    <div class="acc-content">
    Content 3
    </div>
    </div>
    18 changes: 18 additions & 0 deletions common.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@

    $(function() {
    $('.acc-btn').click(function() {
    $('.acc-content').slideUp('normal');
    $('.acc-btn').removeClass('acc-active');
    if ($(this).next().is(':visible') == true) {
    $('.acc-btn').removeClass('active');
    }
    if ($(this).next().is(':hidden') == true) {
    $(this).next().slideDown('normal');
    $(this).addClass('acc-active');
    }
    $('.acc-content').one().removeClass('show');
    });

    $('.acc-content').hide();
    $('.show').show();
    });
    37 changes: 37 additions & 0 deletions style.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@


    .acc-btn {
    display: block;
    position: relative;
    margin-bottom: -2px;
    border-radius: 0;
    color: #fff !important;
    background: #FF9000;
    border: 1px solid #Fff;
    padding: 10px 15px;
    border-bottom: 1px solid transparent;
    font-size: 18px;
    color: inherit;
    cursor: pointer;
    }

    .acc-content {
    padding: 15px;
    }

    .acc-btn:before {
    position: absolute;
    top: 50%;
    right: 15px;
    font-size: 18px;
    z-index: 9999;
    margin-top: -13px;
    font-family: FontAwesome;
    content: "\f078";
    color: #fff;
    }

    .acc-active:before {
    font-family: FontAwesome;
    content: "\f077";
    }