범위가 지정된 맞춤 속성과 애니메이션 타이밍-함수가 있는 애니메이션 CSS 로더를 만들어 보겠습니다.
CodePen으로 이동하여 새 펜을 만듭니다.
로더의 마크업을 만듭니다. 인라인 맞춤 속성 사용에 유의하세요.
<div class="loader" style="--count: 10">
<span style="--index: 0"></span>
<span style="--index: 1"></span>
<span style="--index: 2"></span>
<span style="--index: 3"></span>
<span style="--index: 4"></span>
<span style="--index: 5"></span>
<span style="--index: 6"></span>
<span style="--index: 7"></span>
<span style="--index: 8"></span>
<span style="--index: 9"></span>
</div>
생성기 (Pug)를 사용하여 줄 수를 구성할 수도 있습니다.
- const COUNT = 10
.loader(style=`--count: ${COUNT}`)
- let i = 0
while i < COUNT
span(style=`--index: ${i}`)
- i++
로더에 다음과 같은 스타일을 지정합니다.
loader {
--size: 10vmin;
height: var(--size);
position: relative;
width: var(--size);
}
절대 위치 및 calc
와 transform
의 조합을 사용하여 줄을 배치합니다.
.loader span {
background: grey;
height: 25%;
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%)
rotate(calc(((360 / var(--count)) * var(--index)) * 1deg))
translate(0, -125%);
width: 10%;
}
--index
에 따라 불투명도를 적용합니다.
.loader span {
opacity: calc(var(--index) / var(--count));
}
물건을 돌게 하세요!
.loader {
animation: spin 0.75s infinite steps(var(--count));
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
steps(var(--count))
를 사용하여 올바른 효과를 얻으세요. ✨
완료되었습니다. 🎉
트윗 양식에서 선호하시나요? 🐦
멋지게 꾸미지 마세요! •ᴥ•`