css做钟表,使用css3做钟表

.wrap{width:200px;height:200px;border:2px solid #000;border-radius:50%;margin:100px auto;position:relative;}li{position:absolute;width:2px;height:5px;top:0;left:99px;background:#000;-webkit-transform-origin:center 100px;}

/*li:nth-child(1){-webkit-transform: rotate(0deg);}

li:nth-child(2){-webkit-transform: rotate(6deg);}

li:nth-child(3){-webkit-transform: rotate(12deg);}

li:nth-child(4){-webkit-transform: rotate(18deg);}

li:nth-child(5){-webkit-transform: rotate(24deg);}

li:nth-child(6){-webkit-transform: rotate(30deg);}*/li:nth-child(5n+1){height:10px;}#hour{width:6px;height:40px;background:#000;position:absolute;left:97px;top:60px;-webkit-transform-origin:bottom;}#min{width:4px;height:60px;background:#999;position:absolute;left:98px;top:40px;-webkit-transform-origin:bottom;}#sec{width:2px;height:70px;background:#f00;position:absolute;left:99px;top:30px;-webkit-transform-origin:bottom;}.ico{width:10px;height:10px;background:#000;position:absolute;top:95px;left:95px;border-radius:50%;}

window.οnlοad=function(){varoUl=document.getElementById("list");varoCss=document.getElementById("css");varoHour=document.getElementById("hour");varoMin=document.getElementById("min");varoSec=document.getElementById("sec");varaLi=‘‘;varsss=‘‘;for(vari=0;i<60;i++){

aLi+="

";

sss+=‘li:nth-child(‘+(i+1)+‘){-webkit-transform: rotate(‘+i*6+‘deg);}‘}

oUl.innerHTML=aLi;

oCss.innerHTML+=sss;functiontoTime(){vardate=newDate();varmySec=date.getSeconds();varmyMin=date.getMinutes()+mySec/60;

varmyHour=date.getHours()+myMin/60;

oHour.style.webkitTransform=‘rotate(‘+myHour*30+‘deg)‘;

oMin.style.webkitTransform=‘rotate(‘+myMin*6+‘deg)‘;

oSec.style.webkitTransform=‘rotate(‘+mySec*6+‘deg)‘;

}

toTime();

setInterval(toTime,1000);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
由于我是AI语言模型,无法提供视频演示,以下是文字指导。 首先,需要创建一个钟表的HTML文件,并添加CSS样式。我们可以使用CSS的`transform`属性来实现钟表的简单移动,例如旋转和平移。 HTML代码: ```html <div class="clock"> <div class="hour-hand"></div> <div class="minute-hand"></div> <div class="second-hand"></div> </div> ``` CSS代码: ```css .clock { width: 200px; height: 200px; border-radius: 50%; border: 10px solid #333; position: relative; } .hour-hand { width: 6px; height: 60px; background-color: #333; position: absolute; top: 50%; left: 50%; transform-origin: bottom center; transform: translateX(-50%) rotate(90deg); } .minute-hand { width: 4px; height: 80px; background-color: #333; position: absolute; top: 50%; left: 50%; transform-origin: bottom center; transform: translateX(-50%) rotate(180deg); } .second-hand { width: 2px; height: 100px; background-color: #f00; position: absolute; top: 50%; left: 50%; transform-origin: bottom center; transform: translateX(-50%) rotate(270deg); animation: rotate 60s linear infinite; } @keyframes rotate { from { transform: translateX(-50%) rotate(270deg); } to { transform: translateX(-50%) rotate(630deg); } } ``` 在CSS中,我们定义了一个钟表的容器`.clock`,并为时针、分针、秒针分别定义了样式。其中,`transform-origin`属性指定了旋转的中心点,例如时针和分钟的旋转中心点在底部中心,秒针的旋转中心点在底部中心。 为了使秒针连续移动,我们使用CSS动画,将秒针从270度旋转到630度,动画时间为60秒,以线性方式无限循环。 最后,我们可以通过改变`transform`属性的值,来实现钟表的移动。例如,我们可以使用JavaScript来动态地改变时针、分针、秒针的旋转角度,来模拟时间的流逝。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值