使用方法
const smallCups = document.querySelectorAll(".small-cup");
const litres = document.querySelector(".litres");
const percentage = document.querySelector(".percentage");
const remained = document.querySelector(".remained");
const todaysGoalText = document.querySelector("h5");
const resetButton = document.querySelector(".reset-button");
let totalWater = 3;
let percentValue = 0;
smallCups.forEach((cup, index) => {
cup.addEventListener("click", () => updateBigCup(index));
});
resetButton.addEventListener("click", () => resetLogs());
function updateBigCup(index) {
const logValue = parseInt(smallCups[index].innerHTML);
totalWater -= logValue / 1000;
litres.innerText = totalWater + " L";
percentValue += (logValue / 3000) * 100;
percentage.innerText = percentValue.toFixed(1) + " %";
if (percentValue >= 99) {
litres.innerText = "0 L";
percentage.innerText = "100 %";
todaysGoalText.innerText = "You have achieved your daily goal. Keep it up !";
}
}
function resetLogs() {
totalWater = 3;
percentValue = 0;
litres.innerText = "3.00 L";
percentage.innerText = "0 %";
todaysGoalText.innerText = `Today's goal is : 3 litres`;
}
站长提示:
1. 苦力吧素材官方QQ群:
950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励
2K币。
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服