html - CSS Custom spinner using letter "D"
问题描述
I am trying to create a custom spinner on the letter "D" (as opposed to the animated ellipses, or circle with rotating bar, etc). Here is the code I currently have for the shape of the spinner:
HTML:
<div class="spinnerContainer"></div>
<div class="loader"></div>
CSS:
.spinnerContainer {
width: 40px;
height: 50px;
border-bottom-right-radius: 100px;
border-top-right-radius: 100px;
border: 10px solid gray;
transform: rotate(0deg);
border-top-left-radius: 15px;
border-bottom-left-radius: 15px;
}
I have also included this, as well as the spinner implementation from W3Schools for example purposes, in a jsfiddle here: https://jsfiddle.net/wuvc70sp/1/ but am wondering how I can animate over the "D" similar to the animation on the circle on the W3Schools spinner simply and easily.
I tried using CSS animation to do each component individually (i.e. the vertical line had its own animation, the straight portions on the curve had their own animations, etc.), but it didn't work too well, and didn't seem like an elegant solution either. I am relatively new to more complicated CSS animations, so please excuse me if this is something relatively simple to do.
*** EDIT *** To clarify, I do not want to make the "D" spin. Rather, I want to snake a different color through the "D", as if the "D" was a track, and the color was a car driving laps.
解决方案
只需为此使用 CSS 动画。
.spinner {
width: 40px;
height: 50px;
border-bottom-right-radius: 100px;
border-top-right-radius: 100px;
border: 10px solid gray;
transform: rotate(0deg);
border-top-left-radius: 15px;
border-bottom-left-radius: 15px;
margin: 50px;
animation: 3s spin infinite linear;
}
@keyframes spin {
0% {
transform: rotateZ(0deg);
}
50% {
transform: rotateZ(180deg);
}
100% {
transform: rotateZ(360deg);
}
}
<div class="spinner"></div>
推荐阅读
- airflow-scheduler - 使用 BranchPythonOperator 创建的分支不合并?
- python - 调试器忽略函数中的输入(Python)
- unix - 编译:“sigset_t”的类型冲突
- python - 当我尝试从表单添加时出现白色错误屏幕
- java - 启动 Jitsi 视频通话活动时的问题
- excel - 从不同的工作簿复制并粘贴到 MasterSheet
- html - 使每个输入的标签可点击
- php - 界面中的类型提示
- c - 最小二乘回归线和误差的 C 程序
- unit-testing - SpringBoot 的 MockMVC 测试更适合surefire(mvn test)还是failsafe(mvn verify)?