使用方法
const hourEl = document.querySelector(".hour");
const minuteEl = document.querySelector(".minute");
const secondEl = document.querySelector(".second");
const timeEl = document.querySelector(".time");
const dateEl = document.querySelector(".date");
const toggle = document.querySelector(".toggle");
const days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
];
toggle.addEventListener("click", (e) => {
const body = document.querySelector("body");
if (body.classList.contains("dark")) {
body.classList.remove("dark");
} else {
body.classList.add("dark");
}
});
function setTime() {
const time = new Date();
const month = time.getMonth();
const day = time.getDay();
const date = time.getDate();
const hours = time.getHours();
const hoursForClock = hours % 12;
const minutes = time.getMinutes();
const seconds = time.getSeconds();
hourEl.style.transform = `translate(-50%, -100%) rotate(${
((hoursForClock / 12) * 100 * 360) / 100
}deg)`;
minuteEl.style.transform = `translate(-50%, -100%) rotate(${
((minutes / 60) * 100 * 360) / 100
}deg)`;
secondEl.style.transform = `translate(-50%, -100%) rotate(${
((seconds / 60) * 100 * 360) / 100
}deg)`;
timeEl.innerHTML = `${hours}:${minutes < 10 ? `0${minutes}` : minutes}`;
dateEl.innerHTML = `${days[day]}, ${months[month]} ${date}`;
}
setTime();
setInterval(setTime, 1000);
站长提示:
1. 苦力吧素材官方QQ群:
950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励
2K币。
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服