1 Star 5 Fork 4

zeus1024/电子木鱼

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.js 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
xjchen 提交于 2022-10-22 22:43 . v1.0.0
var mubang = document.querySelector("#mubang");
mubang.addEventListener("click", clickMubang, false);
var muyu = document.querySelector("#muyu");
muyu.addEventListener("click", clickMuyu, false);
var music = document.querySelector("#music");
var auto = document.querySelector("#auto");
// 自动播放音乐
var autoPlayMusic;
// 改变checkbox时触发
auto.addEventListener("change", () => {
if (auto.checked) {
autoPlay();
addNum();
setTimeout(() => {
playMusic();
autoPlayMusic = setInterval(playMusic, 1000);
autoAddNum = setInterval(addNum, 1000);
}, 500);
} else {
clearInterval(autoPlayMusic);
clearInterval(autoAddNum);
document.querySelector(".mubang").className = "mubang";
}
});
// 点击木棒
function clickMubang() {
document.querySelector(".mubang").className = "mubang";
window.requestAnimationFrame(function (time) {
window.requestAnimationFrame(function (time) {
document.querySelector(".mubang").className = "mubang move";
});
});
setTimeout(playMusic, 500);
setTimeout(addNum, 500);
}
// 播放音乐
function playMusic() {
music.play();
}
// 自动敲打木鱼
function autoPlay() {
document.querySelector(".mubang").className = "mubang";
window.requestAnimationFrame(function (time) {
window.requestAnimationFrame(function (time) {
document.querySelector(".mubang").className = "mubang auto_move";
});
});
}
// 点击木鱼
function clickMuyu() {
playMusic();
addNum();
}
// 今日功德,总功德
var todayNum = 0,
allNum = 0;
var today = document.querySelector("#today_count");
var all = document.querySelector("#all_count");
// 初始化获取浏览器保存的功德
getNum();
function getNum() {
if (localStorage.key("todayNum")) {
todayNum = +localStorage.getItem("todayNum");
today.innerHTML = todayNum;
} else {
localStorage.setItem("todayNum", 0);
}
if (localStorage.key("allNum")) {
allNum = +localStorage.getItem("allNum");
all.innerHTML = allNum;
} else {
localStorage.setItem("allNum", 0);
}
}
// 总功德
// 功德+1
function addNum() {
showtips();
setTimeout(hiddenTips, 600);
// 今日功德+1
todayNum = +todayNum + 1;
today.innerHTML = todayNum;
localStorage.setItem("todayNum", todayNum);
// 总功德+1
allNum = +allNum + 1;
all.innerHTML = allNum;
localStorage.setItem("allNum", allNum);
}
// 控制显示功德+1的动画
var tips = document.querySelector("#tips");
function showtips() {
tips.style.visibility = "visible";
tips.style.opacity = "1";
tips.style.top = "50px";
}
function hiddenTips() {
tips.style.visibility = "hidden";
tips.style.opacity = "0";
tips.style.top = "100px";
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zeus10241024/dzmy.git
[email protected]:zeus10241024/dzmy.git
zeus10241024
dzmy
电子木鱼
master

搜索帮助