首页 > 其他分享 >HTML+CSS居然可以做时钟,太秀了吧

HTML+CSS居然可以做时钟,太秀了吧

时间:2023-04-22 17:34:22浏览次数:119  
标签:box span 太秀 height HTML background var border CSS

谁懂啊家人们,html+css居然可以做一个时钟出来,这么厉害的吗

咱这新手是啥也不懂啊,就会复制粘贴,反正是可以正常显示的

话不多说直接上代码,直接复制即可正常运行

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>时钟</title>
        <style>
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }

            section {
                width: 500px;
                height: 500px;
                margin: 50px auto;
                border: 1px solid red;
                background-color: black;
                display: flex;
                align-items: center;
                justify-content: center;
            }

            section .box {
                width: 400px;
                height: 400px;
                border: 10px solid #fff;
                border-radius: 50%;
                background-color: antiquewhite;
                position: relative;
                box-shadow: inset 0px 0px 25px rgb(115,112,112);
                text-align: center;
            }

            section .box div {
                position: absolute;
                left: 0;
                right: 0;
                top: 0;
                margin: auto;
                /* 设置原点 */
                transform-origin: center bottom;
            }

            span {
                font-size: 22px;
                position: absolute;
                height: 100%;
                left: 0;
                right: 0;
                margin: auto;
                padding: 10px;
            }

            span i:nth-of-type(1){
                display: inline-block;
            }

            .center {
                bottom: 0;
                width: 20px;
                height: 20px;
                border-radius: 50%;
                background-color: rgb(0,0,0);
                z-index: 999;
            }

            .shi {
                width: 10px;
                height: 80px;
                background-color: rgb(252,12,12);
                bottom: 80px;
                border-radius: 5px;
            }

            .fen {
                width: 10px;
                height: 100px;
                background-color: rgb(13,0,254);
                bottom: 100px;
                border-radius: 5px;
            }

            .miao {
                width: 10px;
                height: 120px;
                bottom: 120px;
                background-color: rgb(198,255,9);
                border-radius: 5px;
            }
        </style>
    </head>

    <body>
        <section>
            <div class="box">
                <span><i>1</i></span>
                <span><i>2</i></span>
                <span><i>3</i></span>
                <span><i>4</i></span>
                <span><i>5</i></span>
                <span><i>6</i></span>
                <span><i>7</i></span>
                <span><i>8</i></span>
                <span><i>9</i></span>
                <span><i>10</i></span>
                <span><i>11</i></span>
                <span><i>12</i></span>

                <div class="center"></div>
                <div class="shi"></div>
                <div class="fen"></div>
                <div class="miao"></div>
            </div>
        </section>
    </body>

    <script>
        var span = document.querySelectorAll('.box span');
        var is = document.querySelectorAll('.box span i');
        console.log(i);
        for (var i = 0; i < span.length; i++) {
            span[i].style.transform = `rotate(${(i + 1) * 30}deg)`;
            is[i].style.transform = `rotate(${-(i + 1) * 30}deg)`;
        }
    
        var shi = document.querySelector('.shi');
        var fen = document.querySelector('.fen');
        var miao = document.querySelector('.miao');
    
    
        function Time() {
            this.ho = function (h) {
                shi.style.transform = `rotate(${(h * 30)}deg)`
            }
            this.mi = function (f) {
                fen.style.transform = `rotate(${(f * 6)}deg)`
    
            }
            this.se = function (m) {
                miao.style.transform = `rotate(${(m * 6)}deg)`
            }
        }
    
        function move() {
            var date = new Date();
            //秒
            var s = date.getSeconds();
            //分
            var f = date.getMinutes() + s / 60;
            //时
            var h = date.getHours() + f / 60;
            //实例化构造函数
            var time = new Time();
            time.ho(h);
            time.mi(f);
            time.se(s);
        }
        move();
        //计时函数
        setInterval(move, 1000);
    
    </script>
</html>

直接运行就行了,运行好如下图所示,太牛了

 完毕

标签:box,span,太秀,height,HTML,background,var,border,CSS
From: https://www.cnblogs.com/Mickeybo101/p/17343546.html

相关文章

  • Introduction to WebGL 3D with HTML5 and Babylon.js
    Explore3Dbasics,andtakealookat3Dwithouthardware(creatingasoftwareengine).[05:45]-Understanding3DBasicsviaasoftengine[09:49]-UnderstandingtheTransformationpipeline[20:26]-Itsallabouttriangles[31:42]-MovingfromCPUto......
  • 仿chatGPT或chatPDF的前端界面布局,css实现对话聊天布局代码,响应式左右分栏布局(附完整
    chatPDF或者chatGPT的界面挺简洁的,就是一个左侧的列表以及右侧的对话列表,现在使用css实现这样的布局充分运用了flex布局方式实现,左右分栏,以及对话形式展示效果下面是效果图: 在手机设备看就隐藏左侧,右侧100%适应 下面就是html和css的布局代码<style>.chatpdf{......
  • css clear + bfc
    问题:没有设置div2的高度,为什么div1的高度===div2的高度,?解释:当应用于浮动元素时,它将底部元素的外边界边缘移动到所有相关的浮动元素外边界边缘的下方。<divstyle="float:left;clear:both"></div>当应用于非浮动块时,它将非浮动块的边框边界移动到所有相关的浮动元素外边......
  • CSS3: 利用分层动画让元素沿弧形路径运动
    译者注:部分代码示例中可以看效果(作者写在博文里面了…),我偷懒把它做成Gif图了。 CSS的animations(动画)和transitions(变换)擅于实现从点A到点B的直线运动,运动轨迹是直线路径。给一个元素添加了animation或者transition以后,无论你如何调整贝塞尔曲线,都无法让它沿着弧形路......
  • HTML5: 利用SVG动画动态绘制文字轮廓边框线条
    DEMO:点击这里看效果 简要教程这是一款很酷的html5svg线条动态绘制文字轮廓边框动画特效。SVG路径动画在网页设计中是一项热门的技术,它允许我们绘制各种简单、精美的图标和文字。关于使用SVG制作图标方面的知识,请参考阅读ESSENTIALICONS。制作流程先......
  • CSS 基础拾遗(核心知识、常见需求)
    本篇文章围绕了CSS的核心知识点和项目中常见的需求来展开。虽然行文偏长,但较基础,适合初级中级前端阅读,阅读的时候请适当跳过已经掌握的部分。这篇文章断断续续写了比较久,也参考了许多优秀的文章,但或许文章里还是存在不好或不对的地方,请多多指教,可以评论里直接提出来哈。核心......
  • python调用imgkit将html转图片pdf问题实例wkhtmltox
    wkhtmltox的下载地址:https://wkhtmltopdf.org/downloads.html或者:https://github.com/wkhtmltopdf/wkhtmltopdf0.12.6版本按网络上的教程会出现一个错误:IOError:wkhtmltopdfexitedwithnon-zerocode1.error:[blank]解决方法参见:https://stackoverflow.com/questions/......
  • jmeter生成html测试报告(二)
    利用jmeter自带工具:GenerateHTMLreport生成html测试报告:1、打开jmeter测试工具,选择Tools,选择GenerateHTMLreport; 2、完善生成生成报告所需要的内容: 3、点击生成即可 4、根据导出报告的目录即可找到html测试报告了  ......
  • jmeter生成html测试报告(一)
    jmeter如何生成好看且直观的测试报告,可以利用代码生成,也可以利用jmeter自带的工具生成,下面一起了解一下吧!1、首先我们在.jmx文的目录通过cmd进入到dos命令窗口; 2、输入生成报告的代码:jmeter-n-ttest/zhujianwei.jmx-lresult.jtl-e-operformanceReport/#-n:以非GU......
  • css样式 进行的瀑布流玩法
    简单归简单布局还是需要自己造的我是创建了n个相同内容就是换图片<divclass="modulee-content-2"><divclass="content-list"><divclass="aaa"v-for="iteminlineDataList":key="item.id"@click="toDetail(it......