16,874
个编辑
LLWiki正在建设中,欢迎加入我们!
小 |
小 |
||
"use strict";
window.addEventListener('load', function () {
const fromNow = function (ele) {
then = moment(ele.dataset.target),
before = ele.children[1],
after = ele.children[2],
isBefore = then.isBefore(now),
monthsHave31Days = [0, 2, 4, 6, 7, 9, 11]
month = isBefore ? now.month() - then.month() : then.month() - now.month(),
day = isBefore ? now.date() - then.date() : then.date() - now.date(),
hour = isBefore ? now.hour() - then.hour() : then.hour() - now.hour(),
minute = isBefore ? now.minute() - then.minute() : then.minute() - now.minute(),
second = isBefore ? now.second() - then.second() : then.second() - now.second()
if (second < 0) {
minute--;
month += 12;
}
▲ let result = "";
if (year > 0) {
result += `<span class="countdown-num">${year}</` + 'span>年';
if(isBefore) {
before.innerHTML = before.innerHTML.replace("$1", result.replace(/(\d) /g, "$1"));
after.
}
else {
after.innerHTML = after.innerHTML.replace("$1", result.replace(/(\d) /g, "$1"));
before.
}
};
const run = () => {
document.querySelectorAll(".countdownNode:not(.disabled)").forEach((ele) => {
fromNow(ele);
ele.style.visibility = "visible";
});
};
return;
}
});
run();
|