• web实现时钟效果


    纯原生开发时钟效果,话不多说直接上代码。

    HTML标签部分

    <div class="cricles">
            <div class="pointls">
                <!-- 表盘内长刻度 -->
            </div>
            <div class="pointM">
                <!-- 表盘内短刻度 -->
            </div>
            <div class="poniters">
                <div class="point_ho">
                    <!-- 时针 -->
                </div>
                <div class="point_min">
                    <!-- 分针 -->
                </div>
                <div class="point_sec">
                    <!-- 秒针 -->
                </div>
                <span></span>
            </div>
        </div>
    css样式部分
     <style>
            .cricles {
                 300px;
                height: 300px;
                background-color: aqua;
                border-radius: 100%;
                border: 2px solid yellow;
                margin: 100px auto;
                position: relative;
            }
            
            .pointL {
                background-color: red;
                height: 40px;
                 5px;
                position: absolute;
                left: 0;
                right: 0;
                bottom: 0;
                top: 0;
                margin: auto;
            }
            
            .pointS {
                background-color: black;
                height: 20px;
                 5px;
                position: absolute;
                left: 0;
                right: 0;
                bottom: 0;
                top: 0;
                margin: auto;
            }
            
            .poniters {
                position: absolute;
                left: 0;
                right: 0;
                bottom: 0;
                top: 0;
                margin: auto;
                height: 10px;
                 10px;
                /* yellow; */
            }
            
            .poniters div {
                left: 0;
                right: 0;
                bottom: 4px;
                margin: auto;
                position: absolute;
                background-color: tomato;
                height: 60px;
                transform-origin: center bottom;
                 4px;
            }
            
            span {
                 15px;
                height: 15px;
                display: block;
                position: absolute;
                left: -5px;
                right: 0;
                bottom: -5px;
                box-shadow: 0 0 20px black;
                top: 0;
                margin: auto;
                border-radius: 50%;
                background-color: blueviolet;
            }
        </style>
    js部分
    <script>
            //设置表盘大针
            setBigTime();
            setSmallTime();
            setTimePoint();
            setInterval(function() {
                setTimePoint();
            }, 1000);

            function setBigTime() {
                var olis = "";
                var pointList = document.querySelector(".pointls");
                for (var i = 0; i < 12; i++) {
                    olis += `<div class="pointL"></div>`;
                }
                pointList.innerHTML = olis;
                var pointLs = document.querySelectorAll(".pointL");
                // for
                pointLs.forEach(function(v, k) {
                    v.style.transform = ` rotate(${30*k}deg) translateY(130px)`;
                });
            }

            //设置表盘小针
            function setSmallTime() {
                var olis = "";
                var pointList = document.querySelector(".pointM");
                for (var i = 0; i < 60; i++) {
                    olis += `<div class="pointS"></div>`;
                }
                pointList.innerHTML = olis;
                var pointLs = document.querySelectorAll(".pointS");
                // for
                pointLs.forEach(function(v, k) {
                    if ((6 * k) % 30 === 0) {
                        v.style.display = "none";
                    }
                    v.style.transform = ` rotate(${6*k}deg) translateY(140px)`;
                });
            }

            function setTimePoint() {
                var d = new Date();

                var housePoint = document.querySelector(".point_ho");
                housePoint.style.height = "40px";
                housePoint.style.background = "blue";
                housePoint.style.transform = `rotate(${30*d.getHours()}deg)`;

                var minPoint = document.querySelector(".point_min");
                minPoint.style.height = "60px";
                minPoint.style.background = "black";
                minPoint.style.transform = `rotate(${6*d.getMinutes()}deg)`;

                var secPoint = document.querySelector(".point_sec");
                secPoint.style.height = "80px";
                secPoint.style.background = "red";
                secPoint.style.transform = `rotate(${6*d.getSeconds()}deg)`;
            }
        </script>
  • 相关阅读:
    windows和linux双系统删除linux
    亲测 安装windows7
    (转载)Windows 7 Ultimate(旗舰版)SP1 32/64位官方原版下载(2011年5月12日更新版)
    centos6.5 安装
    centos6.3下载地址
    我开启httpd服务的时候 显示Could not reliably determine the server`s fully qualified domain name,
    hibernate 入门
    linux
    java 数据库两种连接方法
    poj 2195 二分图带权匹配+最小费用最大流
  • 原文地址:https://www.cnblogs.com/cyp926/p/13264932.html
Copyright © 2020-2023  润新知