为你的博客添加一个时光飞逝的页面
前序
忘了在哪看到的这个东西,总之看到了一次就忘不掉了
然后就拿我那差的要命的技术写了个这
屎山这个东西还没到这个程度
建议你先将文章过一遍,这样可以更清楚的知道自己下一步要干什么。
这东东貌似有小BUG
%ThemeSource%
位于~\themes\Butterfly\source\
%Source%
位于~\source\
%ThemeLayout%
位于~\themes\Butterfly\layout\
预览
页面正常的话,标题后面不就是的吗?
单独页面
https://blog.admincmd.xyz/favi/
特性
- 支持夜间模式,需要 HTML 标签
- 支持自定义每行精度
引入
引入 JS
这里的代码有可以自己启动、循环的形式,适用于整个页面没有主循环控制器的版本
也有需要在每次循环/触发的形式,适用于有主循环控制器的版本
请根据自己的页面作选择,如果不知道选那种,请选择前者。
代码块单号的是已压缩的代码,多行的是原带注释代码。
适用于自启动、自循环
这个代码随便找个能在页面加载时运行的位置扔着就行,不过建议找个地方放好,以后别忘了( ̄y▽, ̄)╭
1 | let UPDATE_PROGRESS_BARS_INIT=false;function updateProgressBars(){try{let now=new Date();if(UPDATE_PROGRESS_BARS_INIT===false){for(let i=0;i<document.getElementsByClassName('time-flies').length;i++){let length=document.getElementsByClassName('time-flies')[i];length.innerHTML=`<div class="progress-container"><div class="progress-label">今年已经过了<span class="year-progress"></span></div><div class="progress-bar"><div class="year-progress-bar"><span class="year-progress-bar-fill"></span></div></div></div><div class="progress-container"><div class="progress-label">这个月过去了<span class="month-progress"></span></div><div class="progress-bar"><div class="month-progress-bar"></div></div></div><div class="progress-container"><div class="progress-label">今天过去了<span class="day-progress"></span></div><div class="progress-bar">div class="day-progress-bar"></div></div></div><div class="progress-container"><div class="progress-label">这一个小时过了<span class="hour-progress"></span></div><div class="progress-bar"><div class="hour-progress-bar"></div></div></div><div class="progress-container"><div class="progress-label">本分钟过了<span class="minute-progress"></span></div><div class="progress-bar"><div class="minute-progress-bar"></div></div></div><p>珍惜时间,时光飞逝。</p>`}UPDATE_PROGRESS_BARS_INIT=false}const yearStart=new Date(now.getFullYear(),0,1).getTime();const yearEnd=new Date(now.getFullYear()+1,0,1).getTime();const yearProgress=((now.getTime()-yearStart)/(yearEnd-yearStart))*100;const monthStart=new Date(now.getFullYear(),now.getMonth(),1).getTime();const monthEnd=new Date(now.getFullYear(),now.getMonth()+1,1).getTime();const monthProgress=((now.getTime()-monthStart)/(monthEnd-monthStart))*100;const dayStart=new Date(now.getFullYear(),now.getMonth(),now.getDate()).getTime();const dayEnd=new Date(now.getFullYear(),now.getMonth(),now.getDate()+1).getTime();const dayProgress=((now.getTime()-dayStart)/(dayEnd-dayStart))*100;const hourStart=new Date(now.getFullYear(),now.getMonth(),now.getDate(),now.getHours()).getTime();const hourEnd=new Date(now.getFullYear(),now.getMonth(),now.getDate(),now.getHours()+1).getTime();const hourProgress=((now.getTime()-hourStart)/(hourEnd-hourStart))*100;const minuteProgress=(now.getSeconds()*1000+now.getMilliseconds())/1000/60*100;updateDisplay('year',yearProgress,7);updateDisplay('month',monthProgress,6);updateDisplay('day',dayProgress,5);updateDisplay('hour',hourProgress,3);updateDisplay('minute',minuteProgress,2)}catch(error){console.error('更新模块:时光飞逝 时发生错误:',error)}function updateDisplay(period,progress,decimalPlaces){let lengthDiv=document.getElementsByClassName('time-flies');let lengthProgress=document.getElementsByClassName(`${period}-progress`);let lengthProgressBar=document.getElementsByClassName(`${period}-progress-bar`);for(let i=0;i<lengthDiv.length;i++){lengthProgress[i].textContent=progress.toFixed(decimalPlaces)+'%';lengthProgressBar[i].style.width=progress.toFixed(decimalPlaces)+'%'}}}setInterval(updateProgressBars,1000); |
1 | let UPDATE_PROGRESS_BARS_INIT = false; |
主循环的附属
此方式需要你手动将主函数updateProgressBars引入主循环的更新运行块中
有关主循环的
本站的主 JS 是 i.js,在浏览器控制台中可以找到主循环启动的输出,单击索引便可以看到本站的主循环模块。
1 | let UPDATE_PROGRESS_BARS_INIT=false;function updateProgressBars(){try{let now=new Date();if(UPDATE_PROGRESS_BARS_INIT===false){for(let i=0;i<document.getElementsByClassName('time-flies').length;i++){let length=document.getElementsByClassName('time-flies')[i];length.innerHTML=`<div class="progress-container"><div class="progress-label">今年已经过了<span class="year-progress"></span></div><div class="progress-bar"><div class="year-progress-bar"><span class="year-progress-bar-fill"></span></div></div></div><div class="progress-container"><div class="progress-label">这个月过去了<span class="month-progress"></span></div><div class="progress-bar"><div class="month-progress-bar"></div></div></div><div class="progress-container"><div class="progress-label">今天过去了<span class="day-progress"></span></div><div class="progress-bar"><div class="day-progress-bar"></div></div></div><div class="progress-container"><div class="progress-label">这一个小时过了<span class="hour-progress"></span></div><div class="progress-bar"><div class="hour-progress-bar"></div></div></div><div class="progress-container"><div class="progress-label">本分钟过了<span class="minute-progress"></span></div><div class="progress-bar"><div class="minute-progress-bar"></div></div></div><p>珍惜时间,时光飞逝。</p>`}UPDATE_PROGRESS_BARS_INIT=false}const yearStart=new Date(now.getFullYear(),0,1).getTime();const yearEnd=new Date(now.getFullYear()+1,0,1).getTime();const yearProgress=((now.getTime()-yearStart)/(yearEnd-yearStart))*100;const monthStart=new Date(now.getFullYear(),now.getMonth(),1).getTime();const monthEnd=new Date(now.getFullYear(),now.getMonth()+1,1).getTime();const monthProgress=((now.getTime()-monthStart)/(monthEnd-monthStart))*100;const dayStart=new Date(now.getFullYear(),now.getMonth(),now.getDate()).getTime();const dayEnd=new Date(now.getFullYear(),now.getMonth(),now.getDate()+1).getTime();const dayProgress=((now.getTime()-dayStart)/(dayEnd-dayStart))*100;const hourStart=new Date(now.getFullYear(),now.getMonth(),now.getDate(),now.getHours()).getTime();const hourEnd=new Date(now.getFullYear(),now.getMonth(),now.getDate(),now.getHours()+1).getTime();const hourProgress=((now.getTime()-hourStart)/(hourEnd-hourStart))*100;const minuteProgress=(now.getSeconds()*1000+now.getMilliseconds())/1000/60*100;a('year',yearProgress,7);a('month',monthProgress,6);a('day',dayProgress,5);a('hour',hourProgress,3);a('minute',minuteProgress,2)}catch(error){console.error('更新模块:时光飞逝 时发生错误:',error)}function a(c,b,d){let lengthDiv=document.getElementsByClassName('time-flies');let lengthProgress=document.getElementsByClassName(`${c}-b`);let lengthProgressBar=document.getElementsByClassName(`${c}-b-bar`);for(let i=0;i<lengthDiv.length;i++){lengthProgress[i].textContent=b.toFixed(d)+'%';lengthProgressBar[i].style.width=b.toFixed(d)+'%'}}} |
1 | let UPDATE_PROGRESS_BARS_INIT = false; |
引入 CSS
放在合适的位置即可
1 | .time-flies .progress-container{margin-bottom:10px;}.time-flies .progress-label{font-size:14px; margin-bottom:5px;}.time-flies .year-progress-bar,.time-flies .month-progress-bar,.time-flies .day-progress-bar,.time-flies .hour-progress-bar,.time-flies .minute-progress-bar{ width:100%; color:hsla(0,0%,31%,0.24); border-radius:5px; overflow:hidden;text-align:center;line-height:20px;transition:width 0.5s;height:12px;}.time-flies .year-progress-bar,.time-flies .month-progress-bar,.time-flies .day-progress-bar,.time-flies .hour-progress-bar,.time-flies .minute-progress-bar{ content:""; position:absolute;background-image:linear-gradient(-45deg,rgba(255,255,255,0.2) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.2) 50%,rgba(255,255,255,0.2) 75%,transparent 75%,transparent);z-index:1;background-size:50px 50px;animation:move 5s linear infinite;border-top-right-radius:8px;border-bottom-right-radius:8px;border-top-left-radius:20px;border-bottom-left-radius:20px; overflow:hidden;}.time-flies .year-progress-bar{background-color:#4caf50;}.time-flies .month-progress-bar{background-color:#4caf50;}.time-flies .day-progress-bar{background-color:#4caf50;}.time-flies .hour-progress-bar{background-color:#4caf50;}.time-flies .minute-progress-bar{background-color:#4caf50;}html[data-theme="dark"] .time-flies .year-progress-bar{background-color:#2e8330;}html[data-theme="dark"] .time-flies .month-progress-bar{background-color:#2e8330;}html[data-theme="dark"] .time-flies .day-progress-bar{background-color:#2e8330;}html[data-theme="dark"] .time-flies .hour-progress-bar{background-color:#2e8330;}html[data-theme="dark"] .time-flies .minute-progress-bar{background-color:#2e8330;#4caf50;}.time-flies .progress-bar{width:100%;background-color:$color-theme-light-2background;#dddborder-radius:5px;overflow:hidden;}html[data-theme="dark"] .time-flies .progress-bar{background-color:$color-theme-dark-2background}@keyframes move{0%{background-position:0 0;}100%{background-position:50px 50px;}}@-webkit-keyframes move{0%{background-position:0 0;}100%{background-position:50px 50px;}} |
1 | /* 时光飞逝 Home -*/ |
添加
单独页面(适用于Hexo + Butterfly)
创建%ThemeLayout%\includes\page\time.pug
放入以下内容
1 | .time-flies |
找到%ThemeLayout%\page.pug
放入以下内容
1 | extends includes/layout.pug |
插入 + 后面的内容即可,删除 + 号后无需添加空格
创建%Source%\time\index.md
放入以下内容
1 | --- |
hexo g + s 即可看到效果
单独页面或边栏之类的
1 | <div class="time-flies"></div> |
License
(仅包括文中的 JavaScript 和 CSS 代码块)
The MIT License (MIT)
Copyright © 2026 AdminCmd(http://admincmd.xyz)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.





