效果展示
- 倒计时大于一天:显示天数;
- 倒计时小于一天:显示时分秒进行倒计时;
- 如果已经过年了:显示新年快乐;
添加侧边栏
在[Blogroot]\source\_data\widget.yml
文件添加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
top: - class_name: id_name: newYear name: icon: order: 1 html: '<div id="newYear-main"><div class="mask"></div> <p class="title"></p> <div class="newYear-time"></div> <p class="today" style="text-align: right;"></p> </div>'
|
添加css
在[Blogroot]\themes\butterfly\source\css\_custom\
文件夹下新建new-year.styl
文件并添加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #newYear color white padding 0 !important p, h3 font-weight normal color inherit margin 0 .item-headline display none &-main min-height 160px padding 1rem position relative border-radius 12px background-image url('https://img.cdn.tencent-qq.cn/Yize/2023/01/930b82371b2ea955.webp') background-size cover background-position center * position relative line-height 1.3 .newYear-time font-weight bold text-align center .time, .happyNewYear font-size 3.5rem margin 1rem 0 display block .day font-size 5rem .unit font-size 1rem .mask position absolute left 0 top 0 height 100% width 100% background-color rgba(0, 0, 0, .1)
|
引入JQuery和元宝库
在[Blogroot]\_config.butterfly.yml
文件的inject
下的bottom
里添加如下代码:
1 2 3 4
| - <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js" type="application/javascript"></script>
- <script src="https://cdn.wpon.cn/2022-sucai/Gold-ingot.js"></script>
|
添加js
在自定义js
文件中加入以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| var newYear = () => { if (!document.querySelector('#newYear')) return; let newYear = new Date('2023-01-22 00:00:00').getTime() / 1000, week = { 0: '周日', 1: '周一', 2: '周二', 3: '周三', 4: '周四', 5: '周五', 6: '周六' }
time();
function nol(h) { return h > 9 ? h : '0' + h; };
function time() { let now = new Date();
document.querySelector('#newYear .today').innerHTML = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + ' ' + week[now.getDay()]
let second = newYear - Math.round(now.getTime() / 1000);
if (second < 0) { document.querySelector('#newYear .title').innerHTML = 'Happy New Year!'; document.querySelector('#newYear .newYear-time').innerHTML = '<span class="happyNewYear">新年快乐</p>'; } else { document.querySelector('#newYear .title').innerHTML = '距离2023年春节:'
if (second > 86400) { document.querySelector('#newYear .newYear-time').innerHTML = `<span class="day">${Math.ceil(second / 86400)}<span class="unit">天</span></span>` } else { let h = nol(parseInt(second / 3600)); second %= 3600; let m = nol(parseInt(second / 60)); second %= 60; let s = nol(second); document.querySelector('#newYear .newYear-time').innerHTML = `<span class="time">${h}:${m}:${s}</span></span>`; newYearTimer = setTimeout(time, 1000); } } }
jQuery(document).ready(function ($) { $('#newYear').wpSuperSnow({ flakes: ['https://img.cdn.tencent-qq.cn/Yize/2023/01/5258db16c205b467.webp', 'https://img.cdn.tencent-qq.cn/Yize/2023/01/acaf8ad0e1df4bf0.webp', 'https://img.cdn.tencent-qq.cn/Yize/2023/01/0d3789f6ba30bbc2.webp'], totalFlakes: '100', zIndex: '999999', maxSize: '30', maxDuration: '20', useFlakeTrans: false }); }); } newYear();
|
参考链接
22-文章统计图页面
20-链接卡片标签外挂