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