-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (26 loc) · 943 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
let currentPage = 0;
// 从 JSON 文件加载页面数据
fetch('pages.json')
.then(response => response.json())
.then(data => {
const pages = data.pages;
const textElement = document.getElementById('text');
const audioElement = document.getElementById('audio');
function updatePage(index) {
if (index >= 0 && index < pages.length) {
currentPage = index;
textElement.textContent = pages[index].text;
audioElement.src = pages[index].audio;
}
}
// 初始化页面
updatePage(currentPage);
// 添加键盘事件监听
document.addEventListener('keydown', (event) => {
if (event.key === 'ArrowRight') {
updatePage(currentPage + 1);
} else if (event.key === 'ArrowLeft') {
updatePage(currentPage - 1);
}
});
});