使用css3制作时钟动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div class="sad">
    <div class="ke" id="ke1"></div>
    <div class="ke" id="ke2"></div>
    <div class="ke" id="ke3"></div>
    <div class="ke" id="ke4"></div>
    <div class="ke" id="ke5"></div>
    <div class="ke" id="ke6"></div>
    <div id="biaopan">

        <div id="h"></div>
        <div id="i"></div>
        <div id="s"></div>
    </div>
</div>
</div>
<style>
    * {
        padding: 0;
        margin: 0;
    }

    .sad {
        margin: 50px auto;
        width: 300px;
        height: 300px;
        border-radius: 50%;
        border: 10px solid #888888;
        position: relative;

    }

    .ke {
        background-color: #888888;
        width: 8px;
        height: 300px;
        position: absolute;
        left: 50%;
        transform: translate(-50%, 0);
    }

    #ke1, #ke4 {
        width: 10px;
    }

    #ke2 {
        transform: translate(-50%, 0) rotate(30deg);
        /*必须把之前的translate(-50%, 0)加上重新赋值transform属性会把之前的刷新掉 导致旋转中心偏移*/
    }

    #ke3 {
        transform: translate(-50%, 0) rotate(60deg);
    }

    #ke4 {
        transform: translate(-50%, 0) rotate(90deg);
    }

    #ke5 {
        transform: translate(-50%, 0) rotate(120deg);
    }

    #ke6 {
        transform: translate(-50%, 0) rotate(150deg);
    }

    #biaopan {
        position: absolute;
        width: 250px;
        height: 250px;
        border-radius: 50%;
        transform: translate(-50%, -50%);
        left: 50%;
        top: 50%;
        background-color: #fff;
    }

    #h {
        position: absolute;
        width: 6px;
        height: 80px;
        background-color: red;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -100%);
        animation-name: clockAnimate;
        animation-duration: 43200s;
        transition-timing-function: linear;
        animation-iteration-count: infinite;
    }

    #i {
        position: absolute;
        width: 4px;
        height: 100px;
        background-color: green;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -100%);
        animation-name: clockAnimate;
        animation-duration: 3600s;
        transform-origin: 50% 100%;
        animation-iteration-count: infinite;
    }

    #s {
        position: absolute;
        width: 2px;
        height: 120px;
        background-color: hotpink;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -100%);
        animation-name: clockAnimate;
        animation-duration: 60s;
        transform-origin: 50% 100%;
        /*transition-timing-function: steps(60); 谷歌不支持这么写*/
        animation-iteration-count: infinite;
        /*-webkit-animation-timing-function:steps(60);//指针跳格效果*/
        animation-timing-function: steps(60);

    }

    #biaopan:before {
        content: "";
        position: absolute;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        background-color: #000;
        z-index: 200;
    }

    @keyframes clockAnimate {
        from {
            transform: translate(-50%, -100%) rotate(0deg);
        }
        to {
            transform: translate(-50%, -100%) rotate(360deg);
        }
    }

</style>
</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值