li
状态为已关闭和已打开。通过渐变(逐渐)从一个点用CSS转换为另一种颜色
已关闭:颜色是黑色的(没有光线,它们互相折叠)。
打开:颜色是红色(有光线,他们在全视图中)。
我想要的颜色从两个元素之间的点消失,表明影子从枢轴开始,直到他们关闭。我可以看到这样做与施加到其上的梯度伪元素“前”是绝对定位
$('button').on('click', function() {
$(this).toggleClass('active');
});
ul {
width: 320px;
height: auto;
margin: 0 auto;
max-height: 0;
transition: max-height .75s ease-in-out;
overflow: hidden;
}
li {
width: 100%;
height: 50px;
background: #2c3e50;
color: #fff;
text-align: center;
list-style: none;
vertical-align: center;
line-height: 3;
transition: transform .75s ease-in-out, margin .75s ease-in-out, background .75s ease-in-out;
}
button.active + ul {
max-height: 100px;
}
button.active + ul > li {
transform: perspective(320px) rotateX(0deg);
background: #e74c3c;
margin: 0;
}
li.odd {
transform: perspective(320px) rotateX(-90deg);
transform-origin: top;
margin-bottom: -100px;
}
li.even {
border-top: 1px dashed #bf2718;
transform: perspective(320px) rotateX(90deg);
transform-origin: bottom;
margin-top: -100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button>
Toggle
</button>
<ul>
<li class="odd">Lorem</li>
<li class="even">Ipsum</li>
</ul>
我敢肯定,你需要为一个梯度,你不能动画的。 –
是真实的,但你可以假装它,似乎很多工作只是为了一个简单的效果,虽然 – efreeman