用php写一个时钟效果,利用html5制作一个时钟动画效果

b4ce027100669b7a8dfc9358579fa5fb.png

我们先来看下效果图(不考虑颜色搭配):

(学习视频分享:html5视频教程)

a1f3ed09a2e7a4ff20e3fdff3240a80b.png

我们首先要理解如何去实现这个时钟,暂时不要考虑动画,学着将问题进行拆解,一步一步实现。

首先我们需要画个方形,有个边框,给一个圆角就可以实现最外边的圆环再通过一个长的矩形旋转多个就可以实现刻度

82b8c3e13cc63e5f3172270d794ecd7a.png

只要再画一个白色圆面去覆盖就可以实现标准的刻度

236e33e86776b1a24aba13e7b4a85258.png

最后再加上三个矩形和中间的小圆面就可以实现时钟的初始状态了

代码实现

以上过程理解了之后,代码实现就简单多了,唯一需要考虑的就是代码的优化问题,以下为了简单明了每一步是如何实现,存在很多重复的代码。

关于动画,我们只需要设置旋转动画就可以了,时分秒针的动画只需要改变不同的时间就可以了。

具体细节注意见代码:

时钟

*{

padding: 0;

margin: 0;

}

.clock{

width: 300px;

height: 300px;

border: 10px solid #ccc;

/*百分比参照的是实际宽高*/

border-radius: 50%;

margin: 20px auto;

position: relative;

}

.line{

width: 8px;

height: 300px;

background-color: #ccc;

position: absolute;

/*实现居中*/

/*参照父元素的宽*/

left: 50%;

top: 0;

/*参照元素本身*/

transform: translate(-50%,0);

/*保留,否则会被覆盖*/

}

.line2{

transform: translate(-50%,0) rotate(30deg);

}

.line3{

transform: translate(-50%,0) rotate(60deg);

}

.line4{

transform: translate(-50%,0) rotate(90deg);

}

.line5{

transform: translate(-50%,0) rotate(120deg);

}

.line6{

transform: translate(-50%,0) rotate(150deg);

}

.cover{

width: 250px;

height: 250px;

border-radius: 50%;

background-color: #fff;

position: absolute;

left: 50%;

top: 50%;

transform: translate(-50%,-50%);

}

.hour{

width: 6px;

height: 80px;

background-color: red;

position: absolute;

left: 50%;

top: 50%;

transform: translate(-50%,-100%);

/*设置轴心*/

transform-origin: center bottom;

/*动画*/

-webkit-animation: move 43200s linear infinite;

}

.minute{

width: 4px;

height: 90px;

background-color: green;

position: absolute;

left: 50%;

top: 50%;

transform: translate(-50%,-100%);

/*设置轴心*/

transform-origin: center bottom;

/*动画*/

-webkit-animation: move 3600s linear infinite;

}

.second{

width: 2px;

height: 100px;

background-color: blue;

position: absolute;

left: 50%;

top: 50%;

transform: translate(-50%,-100%);

/*设置轴心*/

transform-origin: center bottom;

/*动画*/

-webkit-animation: move 60s infinite steps(60);

/*linear与step(60)重复*/

}

.center{

width:20px;

height:20px;

background-color: #ccc;

border-radius: 50%;

position: absolute;

left: 50%;

top: 50%;

transform: translate(-50%,-50%);

}

/*创建移动动画*/

@keyframes move{

0%{

transform: translate(-50%,-100%) rotate(0deg);

}

100%{

transform: translate(-50%,-100%) rotate(360deg);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值