fetch("https://umami.test.com/api/websites/#{id}/specifystats",{ method: 'GET', headers:{ "Accept":"application/json", "Authorization": "Bearer #{token}" }, }).then(res => res.json()).then(data => { let title = ["今日人数", "今日访问", "昨日人数", "昨日访问", "本月访问", "总访问量"]; let statisticEl = document.getElementById("statistic");
let statistic = []; for (let i = 0; i < data.length; i++) { if (!statisticEl) return; statisticEl.innerHTML += "<div><span>" + title[i] + "</span><span id=" + title[i] + ">" + data[i] + "</span></div>"; queueMicrotask(() => { statistic.push( new CountUp(title[i], 0, data[i], 0, 2, { useEasing: true, useGrouping: true, separator: ",", decimal: ".", prefix: "", suffix: "", }) ); }); }
let statisticElment = document.querySelector(".about-statistic.author-content-item");
function statisticUP() { if (anzhiyu.isInViewPortOfOne(statisticElment)) { for (let i = 0; i < data.length; i++) { queueMicrotask(() => { statistic[i].start(); }); } document.removeEventListener("scroll", throttleStatisticUP); } }
const selfInfoContentYear = new CountUp("selfInfo-content-year", 0, #{selfInfoContentYear}, 0, 2, { useEasing: true, useGrouping: false, separator: ",", decimal: ".", prefix: "", suffix: "", });
let selfInfoContentYearElment = document.querySelector(".author-content-item.selfInfo.single");
function scrollSelfInfoContentYear() { if (selfInfoContentYearElment && anzhiyu.isInViewPortOfOne(selfInfoContentYearElment)) { selfInfoContentYear.start(); document.removeEventListener("scroll", throttleScrollSelfInfoContentYear); } }
const throttleStatisticUP = anzhiyu.throttle(statisticUP, 200); document.addEventListener("scroll", throttleStatisticUP, {passive: true}); statisticUP(); const throttleScrollSelfInfoContentYear = anzhiyu.throttle(scrollSelfInfoContentYear, 200); document.addEventListener("scroll", throttleScrollSelfInfoContentYear, {passive: true}); scrollSelfInfoContentYear(); })
|