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 64 65 66 67 68
| let newYearTimer = null; var newYear = ()=>{ if (clearTimeout(newYearTimer), !document.querySelector("#newYear")) return; let e = new Date("2024-02-10 00:00:00").getTime() / 1e3 , n = { 0: "周日", 1: "周一", 2: "周二", 3: "周三", 4: "周四", 5: "周五", 6: "周六" }; function t(e) { return e > 9 ? e : "0" + e } !function r() { let a = new Date; document.querySelector("#newYear .today").innerHTML = a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日 " + n[a.getDay()]; let l = e - Math.round(a.getTime() / 1e3); if (l < 0) document.querySelector("#newYear .title").innerHTML = "喜迎新年", document.querySelector("#newYear .newYear-time").innerHTML = '<span class="happyNewYear">新年快乐!</span>'; else if (document.querySelector("#newYear .title").innerHTML = "距离2024年春节:", l > 86400) document.querySelector("#newYear .newYear-time").innerHTML = `<span class="day">${Math.ceil(l / 86400)}<span class="unit">天</span></span>`; else { let e = t(parseInt(l / 3600)); l %= 3600; let n = t(parseInt(l / 60)); l %= 60; let a = t(l); document.querySelector("#newYear .newYear-time").innerHTML = `<span class="time">${e}:${n}:${a}</span></span>`, newYearTimer = setTimeout(r, 1e3) } }() }; function newYearSwiper() { var swiper = new Swiper('.newYear-slider', { passiveListeners: true, loop: true, autoplay: { disableOnInteraction: true, delay: 5000 }, effect: 'fade', mousewheel: true, autoHeight: true }); var comtainer = document.querySelector('.newYear-slider'); if (comtainer !== null) { comtainer.onmouseenter = () => { swiper.autoplay.stop() }; comtainer.onmouseleave = () => { swiper.autoplay.start() }; } } function whenDOMReady() { newYear() newYearSwiper() } whenDOMReady(), document.addEventListener("pjax:complete", whenDOMReady);
|