抖音炫酷时间罗盘,2D时间罗盘桌面(免费)用html,css和JavaScript实现

先上图

 背景可以随意更换成自己喜欢的壁纸桌面

 注意:不用修改文件名,替换图片即可,图片一定要和css文件在同级目录。

源码文件在文末

这个css代码块

* {
    margin: 0;
    padding: 0;
}

body {
    font-size: 18px;
    color: #ffffff;
    font-weight: bold;
    font-family: 'Microsoft YaHei', 'Times New Roman', Times, serif;
    background: url(bg30.jpg) no-repeat;
    padding: 0;
    margin: 0;
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover; 
}

.wrap {
    width: 100%;
    height: 100%;
    position: fixed;
    left: 50%;
    top: 50%;
}

ul li {
    list-style: none;
    width: 64px;
    height: 64px;
    line-height: 64px;
    margin: 0;
    text-align: center;
    position: absolute;
    left: -32px;
    top: -32px;
}

/*元素被选中的样式*/
.elementActive {
    color: rgb(118, 7, 155);
    font-weight: bold;
}

 下面是html的部分代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>时间罗盘</title>
        <link href="css/style.css" rel="stylesheet"/>
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </head>

    <body>
        <div class="wrap">
            <div id="yearId">
                <ul>
                    <li class="elementActive">年</li>
                </ul>
            </div>
            <div id="monthId">
                <ul>
                    <li>01月</li>
                    <li>02月</li>
                    <li>03月</li>
                    <li>04月</li>
                    <li>05月</li>
                    <li>06月</li>
                    <li>07月</li>
                    <li>08月</li>
                    <li>09月</li>
                    <li>10月</li>
                    <li>11月</li>
                    <li>12月</li>
                </ul>
            </div>
$(function () {
    /**
     * 旋转元素
     * @param elementId 元素Id
     * @param currNumber 日期数值
     * @param translateNumber 元素距离中心点的距离
     */
    function rotateElement(elementId, currNumber, translateNumber) {
        const $id = $('#' + elementId + ' ul li');
        // 圆所包含的元素个数
        let circleSize = $id.size();
        // 计算平均每个角的弧度
        let circleDeg = 360 / circleSize;
        // 计算角的弧度偏差
        let offsetDeg = circleDeg * currNumber;
        // 对与当前时间匹配的元素添加样式并去除其它元素的样式
        $id.eq(currNumber).addClass('elementActive').siblings().removeClass('elementActive');
        // 渲染所有元素
        for (let i = 0; i < circleSize; ++i) {
            $id.eq(i).css({
                'transition': currNumber === 0 ? '' : '.8s transform',
                'transform': 'rotate(' + (circleDeg * i - offsetDeg) + 'deg) translate(' + translateNumber + 'px, 0px)'
            })
        }
    }

    function init(callback) {
        let date = new Date();
        $("#yearId ul li").text(date.getFullYear() + "年");
        rotateElement('secondId', date.getSeconds(), 305);
        rotateElement('minusId', date.getMinutes(), 255);
        rotateElement('hourId', date.getHours(), 205);
        rotateElement('weekId', date.getDay() - 1, 155);
        rotateElement('dayId', date.getDate() - 1, 115);
        rotateElement('monthId', date.getMonth(), 65);
        rotateElement('yearId', date.getFullYear(), 0);

        (callback instanceof Function) && callback();
    }

    // 先初始化
    init(function () {
        // 循环调度
        setInterval(function () {
            init();
        }, 1000);
    });

});

下期博客教大家如何更换成电脑桌面

 一定要注意压缩包解压后的3个文件一定要在同一个文件夹下,下面时bai度wangpan

链接:https://pan.baidu.com/s/10TOfcUkxJxcNpsYPRItJUg?pwd=1245 
提取码:1245

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柒翼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值