Гладкий Аккордеонный Крах - PullRequest
0 голосов
/ 17 января 2020

Не поймите меня неправильно, я люблю свой аккордеон. Но если бы это было не так резко ... Я смотрел на подобные вопросы, но независимо от того, что я изменяю в своем коде, ничего не работает. Кажется, я не понимаю эту идею. Что мне не хватает в моем коде, чтобы аккордеон открывался и закрывался плавно? Я попытался добавить свойство перехода Easy для различных элементов и изменил иерархию родителей и братьев и сестер, но не повезло.

 var acc = document.getElementsByClassName("panel-header");
    var i;
    for (i = 0; i < acc.length; i++) {
        acc[i].addEventListener("click", function () {
            this.classList.toggle("active");
            var panel = this.nextElementSibling;
            if (panel.style.display === "block") {
                panel.style.display = "none";
            } else {
                panel.style.display = "block";
                panel.style.height = "auto";
            }
        });
    }
.panel-header {
    background-color: #F5F5F5;
    border: 1px solid transparent;
    border-radius: 4px;
    border-color: #ddd;
    width: 100%;
}

h2.null {
    font-size: 27px;
    color: #7F2779;
    font-family: 'Montserrat', sans-serif;
    padding: 10px;
    margin-bottom: 0px;
    cursor: pointer;
}

div i.fa-chevron-down {
    right: 12px;
    left: auto;
    font-size: 26px;
    color: #7f2779;
}

span.active img.align-self-center {
    -webkit-transform: rotate(180deg);
    -ms-transform: rotate(180deg);
    -o-transform: rotate(180deg);
    transform: rotate(180deg);
}

.panel-header.mt-2 {
    position: relative;
}

div img.align-self-center {
    font-size: 18px;
    color: #7f2779;
    -webkit-transition: all 0.6s ease;
    -o-transition: all 0.6s ease;
    transition: all 0.6s ease;
    cursor: pointer;
    float:right;
}

.panel-slide.collapse {
    padding: 2%;
    margin: 0;
    transition: height 400ms linear 0s;
    /*display: none;*/
    overflow: visible;
    z-index: 9999;
    position: relative;
    background-color: rgb(68, 116, 166);
    height: auto;
}
.FAQBox {
    background-color: #4474A6;
    color: white;
    padding: 0;
    min-width: 100px;
    text-align: left;
}

#FAQBottomText {
    text-align: center;
    color: white;
    font-size: 20px;
}
.Collapsible__contentInner {
    padding: 1% 4% 7% 4%;
    background-color: #4474A6;
}
span.panel-header.mt-2.is-closed.active ~ .panel-slide.collapse {
    height: auto;
}
.d-flex.justify-content-between {
    padding: 0 3%;
}
.panel-slide.collapse {
    transition: height 0.25s ease-in;
}
.Collapsible.justify-content-end {
    cursor: pointer;
}
<div class="col-md-12 FAQBox mt-3 mb-2">
                <div class="Collapsible justify-content-end">
                    <span class="panel-header mt-2 is-closed">
                        <div>
                            <div class="d-flex justify-content-between">
                                <h3 class="FAQBoxHeader mt-1">At vero eos et accusamus et iusto odio?</h3>
                                <img class="align-self-center" src="https://www.direct-carexcess.co.uk/dist/ClientApp/Images/Arrow2.png">
                            </div>
                        </div>
                    </span>
                    <div class="panel-slide collapse" style="height: auto; transition: height 400ms linear 0s; display: none;">
                        <div class="Collapsible__contentInner">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</div>
                    </div>
                </div>
            </div>
            <div class="col-md-12 FAQBox mt-3 mb-2">
                <div class="Collapsible justify-content-end">
                    <span class="panel-header mt-2 is-closed">
                        <div>
                            <div class="d-flex justify-content-between">
                                <h3 class="FAQBoxHeader mt-1">At vero eos et ?</h3>
                                <img class="align-self-center" src="https://www.direct-carexcess.co.uk/dist/ClientApp/Images/Arrow2.png">
                            </div>
                        </div>
                    </span>
                    <div class="panel-slide collapse" style="height: auto; transition: height 400ms linear 0s; display: none;">
                        <div class="Collapsible__contentInner">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. </div>
                    </div>
                </div>
            </div>
...