gpt4 book ai didi

javascript - 扩展 Accordion 列表项以保留在 flex 列中

转载 作者:行者123 更新时间:2023-11-30 09:27:19 26 4
gpt4 key购买 nike

在下面的演示中,有两列包含列表项,当我单击列 #2 中的 #6 li 时,#5 li 跳转到第一列。有没有办法确保所有 3 个列表在单击时都留在第 2 列中?

$(function() {
// (Optional) Active an item if it has the class "is-active"
$(".accordion > .accordion-item.is-active").children(".accordion-panel").slideDown();

$(".accordion > .accordion-item").click(function() {
// Cancel the siblings
$(this).siblings(".accordion-item").removeClass("is-active").children(".accordion-panel").slideUp();
// Toggle the item
$(this).toggleClass("is-active").children(".accordion-panel").slideToggle("ease-out");
});
});
ul {
display: flex;
flex-flow: wrap column;
height: 200px; /*to change height to split ul list*/
border: solid 1px red;
}

.accordion {
list-style: none;
}

.accordion-thumb {
margin: 0;
padding: 5px;
cursor: pointer;
font-weight: normal;
}

.accordion-thumb::before {
content: "";
display: inline-block;
height: 7px;
width: 7px;
-webkit-transition: -webkit-transform 0.2s ease-out;
transition: -webkit-transform 0.2s ease-out;
transition: transform 0.2s ease-out;
transition: transform 0.2s ease-out, -webkit-transform 0.2s ease-out;
}

.accordion-panel {
margin: -10px;
display: none;
margin-left: 12px;
padding-bottom: 15px;
}

body {
line-height: 1.5;
margin: 0 auto;
max-width: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="accordion">
<li class="accordion-item is-active">
<h3 class="accordion-thumb">1.) list one</h3>
<p class="accordion-panel">1111111111
</p>
</li>

<li class="accordion-item">
<h3 class="accordion-thumb">2.) list two</h3>
<p class="accordion-panel">2222222222 </p>
</li>

<li class="accordion-item">
<h3 class="accordion-thumb">3.) list three</h3>
<p class="accordion-panel">3333333333
</p>
</li>

<li class="accordion-item">
<h3 class="accordion-thumb">4.) list four </h3>
<p class="accordion-panel">4444444444 </p>
</li>

<li class="accordion-item">
<h3 class="accordion-thumb">5.) list five</h3>
<p class="accordion-panel">5555555555
</p>
</li>

<li class="accordion-item">
<h3 class="accordion-thumb">6.) list six</h3>
<p class="accordion-panel">6666666666 </p>
</li>

<li class="accordion-item">
<h3 class="accordion-thumb">7.) list seven</h3>
<p class="accordion-panel">7777777777
</p>
</li>
</ul>

最佳答案

这是在 css 中使用 Column-count 的解决方案

demo

它确实以不同的方式解决了你的问题

我已经从你的示例代码中更改了这个

添加了一个<li>在第四和第五之间<li>

<li class="column-break">&nbsp;</li>

将 UL 的 css 更改为:

    ul {
height: 200px;
border: solid 1px red;
column-count: 2;
}

<li> 添加了 CSS与类“分栏”

.column-break {
break-after: column;
}

关于javascript - 扩展 Accordion 列表项以保留在 flex 列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48591001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com