这个是看到leonus 后直接搞来的,稍微改了一点点,可以看看他的https://blog.leonus.cn/2023/newYearCard.html 我的是这样的 基本没多大区别,就是元宝飘落多加了个红包,然后倒计时改成了这个鬼样子,他的是到最后一天再启用的时分秒倒计时,我搞成都是的了,换了个背景,字体大小也调了一下。如下以我的为示例。
教程 添加侧边栏 新建根目录\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 自建一个css,添加以下内容
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 60 61 62 63 #newYear { color : white; padding : 0 !important ; } #newYear p ,#newYear h3 { font-weight : normal; color : inherit; margin : 0 ; } #newYear .item-headline { display : none; } #newYear .title { font-size : 1.5rem } #newYear-main { min-height : 160px ; padding : 1rem ; position : relative; border-radius : 12px ; background-image : url (https://z4a.net/images/2023/01/01/9b66af094d71b5642f7e1350b66bc418.jpg ); background-size : cover; background-position : center; } #newYear-main * { position : relative; line-height : 1.3 ; } #newYear-main .newYear-time { font-weight : bold; text-align : center; } #newYear-main .time ,#newYear-main .happyNewYear { font-size : 3rem ; margin : 1rem 0 ; display : block; } #newYear-main .day { font-size : 2rem ; } #newYear-main .day .unit { font-size : 1.5rem ; } #newYear-main .mask { position : absolute; left : 0 ; top : 0 ; height : 100% ; width : 100% ; background-color : rgba (0 , 0 , 0 , .1 ); }
然后在主题配置文件中引入该css,字体大小可以在里面的font-size中修改,其中链接可以自己修改为自己想要的背景
添加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 60 let newYearTimer = null ;var newYear = ( ) => { clearTimeout (newYearTimer); 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 ) { let d = nol (parseInt (second / 86000 )); second %= 86000 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">${d} 天${h} 时${m} 分${s} 秒</span></spa0on>` ; newYearTimer = setTimeout (time, 1000 ); } } } jQuery (document ).ready (function ($ ) { $('#newYear' ).wpSuperSnow ({ flakes : ['https://z4a.net/images/2023/01/02/yb1.webp' , 'https://z4a.net/images/2023/01/02/yb2.webp' , 'https://z4a.net/images/2023/01/02/yb3.webp' , 'https://z4a.net/images/2023/01/02/59dfc0c83d7faa533c46abf6f9076a45-removebg-preview.png' ], totalFlakes : '100' , zIndex : '999999' , maxSize : '30' , maxDuration : '20' , useFlakeTrans : false }); }); } newYear ();
这个主要是实现倒计时和元宝飘落的,元宝飘落里的图片链接可以直接用(还是自己的图床比较好,这个随时跑路),按照格式可以添加修改成你想飘落的东西。
引入JQuery和元宝库 在主题配置文件里(_config.butterfly.yml)的inject下的bottom里添加以下内容
1 2 - <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>
然后就完事,快去试试吧