【发布时间】:2020-06-27 10:53:56
【问题描述】:
我正在制作带有动画时间线的 jQuery 手风琴。它几乎完成了,但我被最后一个元素的线条/动画困住了。您可以在以下位置查看工作示例:https://tjobtjob.nl/goldstine-sales-en-acquisitie-medewerker/。请向下滚动到几乎在底部的名为“Sollicitatieprocedure”的部分。
它适用于所有步骤,除了最后一个。最后一步也显示了一条线,但我希望这条线消失,以便最后一个元素只有一个彩色点。
这是我的 jQuery 代码:
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);
$this.addClass(options.activeClass)
.next().slideDown();
$this.siblings('.' + options.activeClass)
.removeClass(options.activeClass)
.next().slideUp();
}
);
}
);
}
$('dl.stappen').simpleAccordion();
这是 (s)CSS 部分:
dl.stappen{
width: calc(100% - 45px);
display: inline-block;
margin: 50px 0 0;
padding-left: 45px;
position: relative;
dt{
font-weight: 500;
font-size: 21px;
margin-top: 15px;
margin-bottom: 5px;
cursor: pointer;
position: relative;
&:first-of-type{
margin-top: 0;
}
.round{
position: absolute;
left: -45px;
top: 50%;
transform: translateY(-50%);
width: 12px;
height: 12px;
background: #eee;
border: 3px solid #dcae23;
border-radius: 10px;
z-index: 100;
}
}
dd{
font-size: 17px;
line-height: 26px;
position: relative;
p{
margin-bottom: 15px;
&:last-child{
margin-bottom: 0;
}
}
}
&:before{
background: #dcae23;
height: calc(100% - 24px);
width: 3px;
position: absolute;
content: "";
left: 8px;
top: 8px;
}
}
感谢您的帮助!
【问题讨论】:
-
您网站上的 jquery 不起作用。未正确加载,
b950e48fcfd117d6a429f551af01d325.js:1 Uncaught TypeError: $ is not a function -
你能再试一次吗?我清空了缓存
-
onclick最后一个元素,只需添加一个修改css的新类来改变
:after{}height的高度,然后在单击任何其他元素时删除该类 -
谢谢!听起来很简单,但我不是 jQuery 中的明星……您可以稍微修改一下 jQuery 代码以使其正常工作吗?
-
但是您已经在点击代码时添加和删除类?点击添加类和删除类是 jQuery 基础
标签: jquery sass accordion timeline