-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
43 lines (38 loc) · 1.3 KB
/
scripts.js
File metadata and controls
43 lines (38 loc) · 1.3 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
document.addEventListener('DOMContentLoaded', function () {
// 游戏弹窗相关功能
const modal = document.querySelector('.game-modal');
const iframe = document.querySelector('.game-iframe');
const closeBtn = document.querySelector('.close-game');
const playButtons = document.querySelectorAll('.play-button');
// 打开游戏
playButtons.forEach(button => {
button.addEventListener('click', function (e) {
e.preventDefault();
const gameUrl = this.getAttribute('data-game-url');
if (gameUrl) {
iframe.src = gameUrl;
modal.classList.add('active');
document.body.classList.add('modal-open');
}
});
});
// 关闭游戏
function closeModal() {
modal.classList.remove('active');
iframe.src = '';
document.body.classList.remove('modal-open');
}
closeBtn.addEventListener('click', closeModal);
// 点击外部关闭
modal.addEventListener('click', function (e) {
if (e.target === modal) {
closeModal();
}
});
// ESC键关闭
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && modal.classList.contains('active')) {
closeModal();
}
});
});