這篇文章主要介紹純CSS如何實現心形加載動畫,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.heart-loading {
margin-top: 120px;
width: 200px;
height: 200px;
}
ul {
list-style: none;
display: flex;
justify-content: space-between;
width: 150px;
height: 10px;
/* 做心形和條形想法是一樣的,但是每條高度是不一樣的 */
}
li {
--count: 9;
--rgb: calc(var(--index) / var(--count) * .5turn);
/* 不能把這個延時設置的太慢.太慢就看不出來是心形了,同時調整延時和動畫時長即可 */
--time: calc((var(--index) - 1) * 150ms);
border-radius: 5px;
width: 10px;
height: 10px;
background-color: #003BB3;
/* 利用fiter函數可以讓顏色漸變會非常漂亮 */
filter: hue-rotate(var(--rgb));
/* 下邊這個是動畫時長 */
animation-duration: 2.5s;
animation-delay: var(--time);
animation-iteration-count: infinite;
}
.line-1,
.line-9 {
animation-name: line-move-1;
}
.line-2,
.line-8 {
animation-name: line-move-2;
}
.line-3,
.line-7 {
animation-name: line-move-3;
}
.line-4,
.line-6 {
animation-name: line-move-4;
}
.line-5 {
animation-name: line-move-5;
}
/* 對稱的動畫要相同高度,這樣看出心形了 */
@keyframes line-move-1 {
0%,
10%,
90%,
100% {
height: 10px;
}
45%,
55% {
height: 30px;
transform: translate3d(0, -15px, 0);
}
}
@keyframes line-move-2 {
0%,
10%,
90%,
100% {
height: 10px;
}
45%,
55% {
height: 60px;
transform: translate3d(0, -30px, 0);
}
}
@keyframes line-move-3 {
0%,
10%,
90%,
100% {
height: 10px;
}
45%,
55% {
height: 80px;
transform: translate3d(0, -40px, 0);
}
}
@keyframes line-move-4 {
0%,
10%,
90%,
100% {
height: 10px;
}
45%,
55% {
height: 90px;
transform: translate3d(0, -30px, 0);
}
}
@keyframes line-move-5 {
0%,
10%,
90%,
100% {
height: 10px;
}
45%,
55% {
height: 90px;
transform: translate3d(0, -20px, 0);
}
}
</style>
</head>
<body>
<div class="heart-loading">
<ul>
<li class="line-1" style="--index: 1"></li>
<li class="line-2" style="--index: 2"></li>
<li class="line-3" style="--index: 3"></li>
<li class="line-4" style="--index: 4"></li>
<li class="line-5" style="--index: 5"></li>
<li class="line-6" style="--index: 6"></li>
<li class="line-7" style="--index: 7"></li>
<li class="line-8" style="--index: 8"></li>
<li class="line-9" style="--index: 9"></li>
</ul>
</div>
</body>
</html>
css的基本語法是:1、css規則由選擇器和一條或多條聲明兩個部分構成;2、選擇器通常是需要改變樣式的HTML元素;3、每條聲明由一個屬性和一個值組成;4、屬性和屬性值被冒號分隔開。
以上是“純CSS如何實現心形加載動畫”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。