js控制三根指针转动

效果
在这里插入图片描述

html

<body>
    <div id="clock">
        <div class="hms">
            <!-- 时针 -->
            <div class="hour"></div>
            <!-- 分针 -->
            <div class="min"></div>
            <!-- 秒针 -->
            <div class="sec"></div>
        </div>
    </div>
</body>

css

    html,
    body {
        width: 100%;
        height: 100%;
    }

    body,
    ul {
        margin: 0;
    }

    ul {
        padding: 0;
        list-style: none;
    }

    /* clock */
    #clock {
        display: flex;
        -webkit-justify-content: center;
        -moz-justify-content: center;
        -ms-justify-content: center;
        justify-content: center;
        -webkit-align-items: center;
        -ms-align-items: center;
        -moz-align-items: center;
        align-items: center;
        width: 300px;
        height: 300px;
        margin: 60px auto;
        border-radius: 50%;
        box-shadow: 0 0 15px;
    }

    .hms {
        position: relative;
        display: inline-block;
        width: 30px;
        height: 30px;
        background-color: #333;
        border-radius: 50%;
    }

    .hms div {
        position: absolute;
        bottom: 50%;
        background-color: #333;
        transform-origin: center bottom;
    }

    .hms .hour {
        left: calc(50% - 10px/ 2);
        width: 10px;
        height: 80px;
    }

    .hms .hour::after {
        content: "";
        position: absolute;
        left: 0;
        bottom: 79px;
        border-width: 14px 5px;
        border-style: solid;
        border-color: transparent transparent #333 transparent;
    }

    .hms .min {
        left: calc(50% - 8px/ 2);
        width: 8px;
        height: 110px;
        /* transform: rotate(15deg); */
    }

    .hms .min::after {
        content: "";
        position: absolute;
        left: 0;
        bottom: 109px;
        border-width: 12px 4px;
        border-style: solid;
        border-color: transparent transparent #333 transparent;
    }

    .hms .sec {
        left: calc(50% - 6px/ 2);
        width: 6px;
        height: 120px;
        /* transform: rotate(30deg); */
    }

    .hms .sec::after {
        content: "";
        position: absolute;
        left: 0;
        bottom: 119px;
        border-width: 10px 3px;
        border-style: solid;
        border-color: transparent transparent #333 transparent;
    }
</style>

js

    var doc = document;
    var ele = {
        eleHour: doc.getElementsByClassName("hour")[0],
        eleMin: doc.getElementsByClassName("min")[0],
        eleSec: doc.getElementsByClassName("sec")[0],
    };

    // 控制指针随便转
    function rotating(val1,val2,val3) {
        ele.eleSec.style.transform = "rotate(" + val1 + "deg)";
        ele.eleMin.style.transform = "rotate(" + val2 + "deg)";
        ele.eleHour.style.transform = "rotate(" + val3 + "deg)";
    }
    rotating(120,200,350)
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值