首页 学习快乐📔,爱好兴趣🌌

说明

站长通过学习得来,多有不易,如有帮助,请点赞支持


1、首先你先复制这段代码到sidebar.php处

<div class="sidebar-box classListBox">
         <div class="aside aside-count">
            <div class="p-3">人生倒计时</div>
            <div class="content">
                <div class="item" id="dayProgress">
                    <div class="title">今日已经过去<span></span>小时</div>
                    <div class="progress">
                        <div class="progress-bar">
                            <div class="progress-inner progress-inner-1"></div>
                        </div>
                        <div class="progress-percentage"></div>
                    </div>
                </div>
                <div class="item" id="weekProgress">
                    <div class="title">这周已经过去<span></span>天</div>
                    <div class="progress">
                        <div class="progress-bar">
                            <div class="progress-inner progress-inner-2"></div>
                        </div>
                        <div class="progress-percentage"></div>
                    </div>
                </div>
                <div class="item" id="monthProgress">
                    <div class="title">本月已经过去<span></span>天</div>
                    <div class="progress">
                        <div class="progress-bar">
                            <div class="progress-inner progress-inner-3"></div>
                        </div>
                        <div class="progress-percentage"></div>
                    </div>
                </div>
                <div class="item" id="yearProgress">
                    <div class="title">今年已经过去<span></span>个月</div>
                    <div class="progress">
                        <div class="progress-bar">
                            <div class="progress-inner progress-inner-4"></div>
                        </div>
                        <div class="progress-percentage"></div>
                    </div>
                </div>
            </div>
        </div>
</div>

2、下载我提供的这个进度条css美化文件,或者直接引用到<head>头部标签内

https://blog.yshgg.cn/usr/themes/Cuteen/static/css/jdt.css

    <link rel="stylesheet" href="https://blog.yshgg.cn/usr/themes/Cuteen/static/js/jdt.css" />

3、有以上代码还不够,还缺少样式

我把它放在我的css文件里面,发现还是不对(这个问题待解决),所以就放在了sidebar.php下面,尽管这样会显得臃肿。

<style>
    
.dark-mode .comment-card .comment-info, .dark-mode .modal-header {
    border-bottom: 1px dashed rgba(0, 0, 0, 0.5);
}
.dark-mode .modal-footer, .dark-mode .sidebar-info {
    border-top: 1px dashed rgba(0, 0, 0, 0.5);
}
.dark-mode .sidebar-box {
    border: 1px solid rgba(0, 0, 0, 0.2);
}
.aside-count .content {
    padding: 15px
}

.aside-count .content .item {
    margin-bottom: 15px
}

.aside-count .content .item:last-child {
    margin-bottom: 0
}

.aside-count .content .item .title {
    font-size: 12px;
    color: var(--minor);
    margin-bottom: 5px;
    display: flex;
    align-items: center
}

.aside-count .content .item .title span {
    color: var(--theme);
    font-weight: 500;
    font-size: 14px;
    margin: 0 5px
}
.aside-count .content .item .progress {
    display: flex;
    align-items: center
}

.aside-count .content .item .progress .progress-bar {
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    background: var(--classC);
    width: 0;
    min-width: 0;
    flex: 1;
    margin-right: 5px
}
@keyframes progress {
    0% {
        background-position: 0 0
    }

    100% {
        background-position: 30px 0
    }
}
.aside-count .content .item .progress .progress-bar .progress-inner {
    width: 0;
    height: 100%;
    border-radius: 5px;
    transition: width 0.35s;
    -webkit-animation: progress 750ms linear infinite;
    animation: progress 750ms linear infinite
}

.aside-count .content .item .progress .progress-bar .progress-inner-1 {
    background: #bde6ff;
    background-image: linear-gradient(135deg, #50bfff 25%, transparent 25%, transparent 50%, #50bfff 50%, #50bfff 75%, transparent 75%, transparent 100%);
    background-size: 30px 30px
}

.aside-count .content .item .progress .progress-bar .progress-inner-2 {
    background: #ffd980;
    background-image: linear-gradient(135deg, #f7ba2a 25%, transparent 25%, transparent 50%, #f7ba2a 50%, #f7ba2a 75%, transparent 75%, transparent 100%);
    background-size: 30px 30px
}

.aside-count .content .item .progress .progress-bar .progress-inner-3 {
    background: #ffa9a9;
    background-image: linear-gradient(135deg, #ff4949 25%, transparent 25%, transparent 50%, #ff4949 50%, #ff4949 75%, transparent 75%, transparent 100%);
    background-size: 30px 30px
}

.aside-count .content .item .progress .progress-bar .progress-inner-4 {
    background: #67c23a;
    background-image: linear-gradient(135deg, #4f9e28 25%, transparent 25%, transparent 50%, #4f9e28 50%, #4f9e28 75%, transparent 75%, transparent 100%);
    background-size: 30px 30px
}

.aside-count .content .item .progress .progress-percentage {
    color: var(--info)
}
</style>

4、这时候又出现一个问题,没有自动获取到时间

还需要一个timeinfo.js来控制时间,这里可以选择直接引用我的https://blog.yshgg.cn/usr/themes/Cuteen/static/js/timeinfo.js
或者保存到自己的本地

function init_life_time() {
            function getAsideLifeTime() {
                /* 当前时间戳 */
                let nowDate = +new Date();
                /* 今天开始时间戳 */
                let todayStartDate = new Date(new Date().toLocaleDateString()).getTime();
                /* 今天已经过去的时间 */
                let todayPassHours = (nowDate - todayStartDate) / 1000 / 60 / 60;
                /* 今天已经过去的时间比 */
                let todayPassHoursPercent = (todayPassHours / 24) * 100;
                $('#dayProgress .title span').html(parseInt(todayPassHours));
                $('#dayProgress .progress .progress-inner').css('width', parseInt(todayPassHoursPercent) + '%');
                $('#dayProgress .progress .progress-percentage').html(parseInt(todayPassHoursPercent) + '%');
                /* 当前周几 */
                let weeks = {
                    0: 7,
                    1: 1,
                    2: 2,
                    3: 3,
                    4: 4,
                    5: 5,
                    6: 6
                };
                let weekDay = weeks[new Date().getDay()];
                let weekDayPassPercent = (weekDay / 7) * 100;
                $('#weekProgress .title span').html(weekDay);
                $('#weekProgress .progress .progress-inner').css('width', parseInt(weekDayPassPercent) + '%');
                $('#weekProgress .progress .progress-percentage').html(parseInt(weekDayPassPercent) + '%');
                let year = new Date().getFullYear();
                let date = new Date().getDate();
                let month = new Date().getMonth() + 1;
                let monthAll = new Date(year, month, 0).getDate();
                let monthPassPercent = (date / monthAll) * 100;
                $('#monthProgress .title span').html(date);
                $('#monthProgress .progress .progress-inner').css('width', parseInt(monthPassPercent) + '%');
                $('#monthProgress .progress .progress-percentage').html(parseInt(monthPassPercent) + '%');
                let yearPass = (month / 12) * 100;
                $('#yearProgress .title span').html(month);
                $('#yearProgress .progress .progress-inner').css('width', parseInt(yearPass) + '%');
                $('#yearProgress .progress .progress-percentage').html(parseInt(yearPass) + '%');
            }
            getAsideLifeTime();
            setInterval(() => {
                getAsideLifeTime();
            }, 1000);
        }
init_life_time()

5、最后还得在sidebar.php文件最下部引用

<script async src="https://blog.yshgg.cn/usr/themes/Cuteen/static/js/timeinfo.js"></script> 
## 注意! 直接复制可能会有删除空格的现象,暂时需要手动删除空格,要不代码不会生效! 最终就可以实现和本站相同的效果。通过别人的网站学习到的内容,在这里给大家分享分享经验



文章评论

    杰宝宝 访客ChromeAndroid
    2021-01-19 11:52   回复

    明白了,我试试

    杰宝宝 访客ChromeWindows
    2021-01-19 11:12   回复

    引用你的,但是不显示时间,

      小妖 站长ChromeWindows
      2021-01-19 11:13   回复

      网站加个悬挂猫就好了

        杰宝宝 访客ChromeWindows
        2021-01-19 11:29   回复

        什么意思?小白不太明白

          小妖 站长ChromeWindows
          2021-01-19 11:32   回复

          噢不是,你看你引用的代码对没有,直接复制的话,会出错

            杰宝宝 访客ChromeWindows
            2021-01-19 11:36   回复

            代码删隔过,不知道对不对

              小妖 站长ChromeWindows
              2021-01-19 11:38   回复

              最后一个引用代码那里,中间需要你自己添加上空格哦,然后网站还要引用jQuery,你看有没有这个文件

    SolaKing 访客ChromeWindows
    2020-12-30 17:21   回复

    dalao我又来了

      小妖 站长ChromeWindows
      2020-12-30 17:23   回复