Этот пример должен помочь вам. Поиграйте с ослаблениями в css и добавьте их к slideUp()
& slideDown()
, если хотите.
Это можно сделать, просто добавив и удалив класс при нажатии ...
if ($this.text().trim() == "Step three") {
$(".stappen").addClass("reduce");
} else {
$(".stappen").removeClass("reduce");
}
И используя следующее CSS
dl.stappen:before {
....
transition: height linear 400ms;
}
dl.stappen.reduce::before {
height: calc(64% - 45px);
}
Вам потребуется измените текст в JS и ваш рост в calc
соответственно.
jQuery.fn.simpleAccordion = function(options) {
options = $.extend({ start: 0, activeClass: "active" }, options || {});
return this.each(function() {
var $this = $(this);
var headers = $this.children("dt");
headers.next().hide();
headers
.eq(options.start)
.addClass(options.activeClass)
.next()
.show();
headers.bind("click", function() {
var $this = $(this);
if ($this.text().trim() == "Step three") {
$(".stappen").addClass("reduce");
} else {
$(".stappen").removeClass("reduce");
}
$this
.addClass(options.activeClass)
.next()
.slideDown();
$this
.siblings("." + options.activeClass)
.removeClass(options.activeClass)
.next()
.slideUp();
});
});
};
$("dl.stappen").simpleAccordion();
dl.stappen {
width: calc(100% - 45px);
display: inline-block;
margin: 50px 0 0;
padding-left: 45px;
position: relative;
}
dl.stappen dt {
font-weight: 500;
font-size: 21px;
margin-top: 15px;
margin-bottom: 5px;
cursor: pointer;
position: relative;
}
dl.stappen dt:first-of-type {
margin-top: 0;
}
dl.stappen dt .round {
position: absolute;
left: -45px;
top: 50%;
transform: translateY(-50%);
width: 12px;
height: 12px;
background: #eee;
border: 3px solid black;
border-radius: 10px;
z-index: 100;
}
dl.stappen dd {
font-size: 17px;
line-height: 26px;
position: relative;
}
dl.stappen dd p {
margin-bottom: 15px;
}
dl.stappen dd p:last-child {
margin-bottom: 0;
}
dl.stappen:before {
background: black;
height: calc(100% - 24px);
width: 3px;
position: absolute;
content: "";
left: 8px;
top: 8px;
transition: height linear 400ms;
}
dl.stappen.reduce::before {
height: calc(64% - 45px);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<dl class="stappen">
<dt>
<div class="round"></div>
Step one
</dt>
<dd>
Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description. Step one description.
</dd>
<dt>
<div class="round"></div>
Step two
</dt>
<dd>
Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description. Step two description.
</dd>
<dt>
<div class="round"></div>
Step three
</dt>
<dd>
Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description. Step three description.
</dd>
</dl>