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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| //- Umami 统计 和 51LA 统计 if theme.Umami && theme.Umami.enable script(defer). (function() { const umamiApiUrl = "#{url_for(theme.Umami.umami_api)}"; fetch(umamiApiUrl) .then(res => res.json()) .then(data => { let title = { "today_uv": "今日人数", "today_pv": "今日访问", "yesterday_uv": "昨日人数", "yesterday_pv": "昨日访问", "last_month_pv": "本月访问", "last_year_pv": "本年访问" }; let s = document.getElementById("statistic"); for (let key in data) { if (data.hasOwnProperty(key) && title[key]) { s.innerHTML += `<div><span>${title[key]}</span><span id="${key}">${data[key]}</span></div>`; } } initCountUp(data, title); }) .catch(error => console.error('Error:', error)); })(); else script(defer). function initAboutPage() { fetch("https://v6-widget.51.la/v6/#{ck}/quote.js") .then(res => res.text()) .then(data => { let title = ["最近活跃", "今日人数", "今日访问", "昨日人数", "昨日访问", "本月访问", "总访问量"]; let num = data.match(/(<\/span><span>).*?(\/span><\/p>)/g);
num = num.map(el => { let val = el.replace(/(<\/span><span>)/g, ""); let str = val.replace(/(<\/span><\/p>)/g, ""); return str; });
let statisticEl = document.getElementById("statistic");
// 自定义不显示哪个或者显示哪个,如下为不显示 最近活跃访客 和 总访问量 let statistic = []; for (let i = 0; i < num.length; i++) { if (!statisticEl) return; if (i == 0) continue; statisticEl.innerHTML += "<div><span>" + title[i] + "</span><span id=" + title[i] + ">" + num[i] + "</span></div>"; queueMicrotask(() => { statistic.push( new CountUp(title[i], 0, num[i], 0, 2, { useEasing: true, useGrouping: true, separator: ",", decimal: ".", prefix: "", suffix: "", }) ); }); }
let statisticElement = document.querySelector(".about-statistic.author-content-item"); function statisticUP() { if (!statisticElement) return;
const callback = (entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { for (let i = 0; i < num.length; i++) { if (i == 0) continue; queueMicrotask(() => { statistic[i - 1].start(); }); } observer.disconnect(); // 停止观察元素,因为不再需要触发此回调 } }); };
const options = { root: null, rootMargin: "0px", threshold: 0 }; const observer = new IntersectionObserver(callback, options); observer.observe(statisticElement); }
statisticUP(); initCountUp({}, {}); });
initAnimation(); } if (typeof gsap === "object") { initAboutPage() } else { getScript("!{url_for(theme.asset.gsap_js)}").then(initAboutPage); }
//- 初始化 countup.js script(defer). function initCountUp(data, title) { const elements = [];
for (let key in data) { if (data.hasOwnProperty(key) && title[key]) { const element = document.getElementById(key); if (element) { elements.push({ id: key, value: data[key], element: element }); } } }
const selfInfoContentYearElement = document.getElementById("selfInfo-content-year"); if (selfInfoContentYearElement) { elements.push({ id: "selfInfo-content-year", value: #{selfInfoContentYear}, element: selfInfoContentYearElement }); }
const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { const target = elements.find(el => el.element === entry.target); if (target) { const countUp = new CountUp(target.id, 0, target.value, 0, 2, { useEasing: true, useGrouping: target.id === "selfInfo-content-year" ? false : true, separator: ",", decimal: ".", prefix: "", suffix: "", }); countUp.start(); observer.unobserve(entry.target); } } }); }, { threshold: 0 });
elements.forEach(el => observer.observe(el.element)); }
//- 独立鼠标跟随动画 script(defer). function initAnimation() { var pursuitInterval = null; pursuitInterval = setInterval(function () { const show = document.querySelector("span[data-show]"); const next = show.nextElementSibling || document.querySelector(".first-tips"); const up = document.querySelector("span[data-up]");
if (up) { up.removeAttribute("data-up"); }
show.removeAttribute("data-show"); show.setAttribute("data-up", "");
next.setAttribute("data-show", ""); }, 2000);
document.addEventListener("pjax:send", function () { pursuitInterval && clearInterval(pursuitInterval); });
var helloAboutEl = document.querySelector(".hello-about"); helloAboutEl.addEventListener("mousemove", evt => { const mouseX = evt.offsetX; const mouseY = evt.offsetY; gsap.set(".cursor", { x: mouseX, y: mouseY, });
gsap.to(".shape", { x: mouseX, y: mouseY, stagger: -0.1, }); }); } if (typeof gsap === "object") { initAnimation() } else { getScript("!{url_for(theme.asset.gsap_js)}").then(initAnimation); }
|