我希望在选中特定复选框时更改垂直时间轴的高度。例如,在CSS组件中,选中复选框时应更改高度%
.timeline:before {
top: 0;
bottom: 0;
position: absolute;
content: " ";
width: 10px;
height:100%;
background-color: #ccc;
transition: all 0.3s;
left: 49.7%;
margin-left: -1.5px;
}
这是我的HTML组件代码
<div class="container">
<div class="page-header">
<h1 id="timeline">Timeline</h1>
<ul>
<li><input type="checkbox">height 8%</li>
<li><input type="checkbox">height 25%</li>
<li><input type="checkbox">height 38%</li>
<li><input type="checkbox">height 53%</li>
<li><input type="checkbox">height 72%</li>
<li><input type="checkbox">height 100%</li>
</ul>
</div>
<ul class="timeline">
<li>
<div class="timeline-badge"><button><i class="fa fa-times"></i></button></div>
<div class="timeline-panel">
<p>Sponsor Approval</p>
</div>
</li>
<li class="timeline-inverted">
<div class="timeline-badge"><button><i class="fa fa-times"></i></button></div>
<div class="timeline-panel">
<p>Initial Payment</p>
</div>
</li>
<li>
<div class="timeline-badge"><button><i class="fa fa-times"></i></button></div>
<div class="timeline-panel">
<p>HR Approved Date</p>
</div>
</li>
<li class="timeline-inverted">
<div class="timeline-badge"><button><i class="fa fa-times"></i></button></div>
<div class="timeline-panel">
<p>Manager Approved Date</p>
</div>
</li>
<li>
<div class="timeline-badge"><button><i class="fa fa-times"></i></button></div>
<div class="timeline-panel">
<p>Letter of intent</p>
</div>
</li>
<li class="timeline-inverted">
<div class="timeline-badge"><button><i class="fa fa-times"></i></button></div>
<div class="timeline-panel">
<p>Final Offer Leter</p>
</div>
</li>
</ul>
这是我的CSS组件代码
h1{
text-align: center;
}
.timeline {
list-style: none;
padding: 20px 0 20px;
position: relative;
}
button{
border: none;
background-color: transparent;
}
p{
text-align: center;
}
.timeline:before {
top: 0;
bottom: 0;
position: absolute;
content: " ";
width: 10px;
height:100%;
background-color: #ccc;
transition: all 0.3s;
left: 49.7%;
margin-left: -1.5px;
}
.h8{
height: 8%;
}
.timeline > li {
margin-bottom: 2cm;
position: relative;
}
.timeline > li:before,
.timeline > li:after {
content: " ";
display: table;
}
.timeline > li:after {
clear: both;
}
.timeline > li:before,
.timeline > li:after {
content: " ";
display: table;
}
.timeline > li:after {
clear: both;
}
.timeline > li > .timeline-panel {
width: 46%;
height: 2cm;
float: left;
border: 1px solid #d4d4d4;
border-radius: 25px;
padding: 20px;
position: relative;
-webkit-box-shadow: 0 1px 6px rgba(0, 0, 0, 0.175);
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.175);
}
.timeline > li > .timeline-panel:before {
position: absolute;
top: 26px;
right: -15px;
display: inline-block;
border-top: 15px solid transparent;
border-left: 15px solid #ccc;
border-right: 0 solid #ccc;
border-bottom: 15px solid transparent;
content: " ";
}
.timeline > li > .timeline-panel:after {
position: absolute;
top: 27px;
right: -14px;
display: inline-block;
border-top: 14px solid transparent;
border-left: 14px solid #fff;
border-right: 0 solid #fff;
border-bottom: 14px solid transparent;
content: " ";
}
.timeline > li > .timeline-badge {
color: #fff;
width: 50px;
height: 50px;
line-height: 50px;
font-size: 1.4em;
text-align: center;
position: absolute;
top: 16px;
left: 50%;
margin-left: -25px;
background-color: #999999;
z-index: 100;
border-top-right-radius: 50%;
border-top-left-radius: 50%;
border-bottom-right-radius: 50%;
border-bottom-left-radius: 50%;
}
.timeline > li.timeline-inverted > .timeline-panel {
float: right;
}
.timeline > li.timeline-inverted > .timeline-panel:before {
border-left-width: 0;
border-right-width: 15px;
left: -15px;
right: auto;
}
.timeline > li.timeline-inverted > .timeline-panel:after {
border-left-width: 0;
border-right-width: 14px;
left: -14px;
right: auto;
}
.timeline-title {
margin-top: 0;
color: inherit;
}
.timeline-body > p,
.timeline-body > ul {
margin-bottom: 0;
}
.timeline-body > p + p {
margin-top: 5px;
}
@media (max-width: 767px) {
ul.timeline:before {
left: 40px;
}
ul.timeline > li > .timeline-panel {
width: calc(100% - 90px);
width: -moz-calc(100% - 90px);
width: -webkit-calc(100% - 90px);
}
ul.timeline > li > .timeline-badge {
left: 15px;
margin-left: 0;
top: 16px;
}
ul.timeline > li > .timeline-panel {
float: right;
}
ul.timeline > li > .timeline-panel:before {
border-left-width: 0;
border-right-width: 15px;
left: -15px;
right: auto;
}
ul.timeline > li > .timeline-panel:after {
border-left-width: 0;
border-right-width: 14px;
left: -14px;
right: auto;
}
}
1条答案
按热度按时间ee7vknir1#
据我所知,
checkbox
不是适合这项工作的工具。checkbox
通常用于可以选择多个元素的情况。这里似乎不是这种情况。您可能希望时间轴的高度为8%或100%,但不能同时为两者。应该使用一个select
或一组radio-buttons
,然后需要一个可选高度的数组,以及组件中当前选定的高度:在模板中,只需迭代该数组并为每个数组创建一个select选项,还需要将
selectedHeight
绑定到该select元素,以便引用其当前值:最后,您现在可以使用
selectedHeight
控制时间轴高度元素:这种方法有一个主要优点:你只需要改变数组的值就可以控制可选的高度。这些值现在甚至可以来自服务,从数据库或配置文件中获取。