要制作带有图表和「发条」风格的时钟效果,需要运用CSS3中的transform属性和animation属性。
首先,需要用HTML创建一个圆形的时钟盘,在其中添加时针、分针和秒针。代码如下:
<div class="clock"> <div class="hour"></div> <div class="minute"></div> <div class="second"></div> </div>
接下来,使用CSS对时钟进行样式设置。首先,设置时钟盘的样式:
.clock { position: relative; width: 200px; height: 200px; border-radius: 50%; border: 2px solid #333; background-color: #f5f5f5; }
然后,分别设置时针、分针和秒针的样式,并使用transform属性将它们旋转到正确的位置:
.hour, .minute, .second { position: absolute; width: 4px; height: 4px; background-color: #333; border-radius: 50%; transform-origin: bottom center; }.hour { height: 40px; transform: rotate(30deg); }
.minute { height: 70px; transform: rotate(180deg); }
.second { height: 100px; background-color: #e74c3c; transform: rotate(270deg); }
最后,添加动画效果,让秒针和「发条」动起来:
.second { animation: move 60s linear infinite; }@keyframes move { 0% { transform: rotate(270deg); } 100% { transform: rotate(630deg); } }
.clock:before { content: ""; position: absolute; top: -10px; left: 50%; width: 0; height: 0; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-right: 50px solid #333; transform: translateX(-50%); }
.clock:after { content: ""; position: absolute; bottom: -20px; left: 50%; width: 0; height: 0; border-top: 20px solid transparent; border-bottom: 20px solid transparent; border-left: 100px solid #333; transform: translateX(-50%) rotate(-90deg); animation: rotate 60s linear infinite; }
@keyframes rotate { 0% { transform: translateX(-50%) rotate(-90deg); } 100% { transform: translateX(-50%) rotate(270deg); } }
以上就是制作带有图表和「发条」风格的时钟效果的完整代码。