Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
740 lines (718 loc) · 32.5 KB
/
Copy pathindex.html
File metadata and controls
740 lines (718 loc) · 32.5 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title data-i18n="title">Nuitka-GUI-Packager - Nuitka 图形化打包工具</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/21.6.14/i18next.min.js"></script>
<style>
:root {
--primary-green: #10b981;
--primary-green-light: #34d399;
--primary-green-dark: #059669;
--secondary-green: #6ee7b7;
--accent-green: #a7f3d0;
--dark-bg: #0f172a;
--dark-card: #1e293b;
--text-primary: #f1f5f9;
--text-secondary: #cbd5e1;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, var(--dark-bg) 0%, #1e293b 100%);
color: var(--text-primary);
line-height: 1.6;
overflow-x: hidden;
}
.particles {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
pointer-events: none;
}
.particle {
position: absolute;
background: var(--primary-green);
border-radius: 50%;
opacity: 0.6;
animation: float 6s ease-in-out infinite;
}
@keyframes float {
0%, 100% { transform: translateY(0px) rotate(0deg); }
50% { transform: translateY(-20px) rotate(180deg); }
}
.header {
background: rgba(15, 23, 42, 0.8);
backdrop-filter: blur(10px);
padding: 1rem 2rem;
position: fixed;
width: 100%;
top: 0;
z-index: 1000;
border-bottom: 1px solid rgba(16, 185, 129, 0.2);
}
.nav {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 1200px;
margin: 0 auto;
}
.logo {
font-size: 1.5rem;
font-weight: 700;
background: linear-gradient(to right, var(--primary-green), var(--secondary-green));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
display: flex;
align-items: center;
gap: 0.5rem;
}
.nav-links {
display: flex;
gap: 2rem;
align-items: center; /* 垂直居中对齐链接和语言切换器 */
}
.nav-link {
color: var(--text-secondary);
text-decoration: none;
transition: all 0.3s ease;
font-weight: 500;
}
.nav-link:hover {
color: var(--primary-green);
transform: translateY(-2px);
}
.language-switcher {
display: flex;
gap: 0.5rem;
}
.lang-btn {
background: transparent;
color: var(--text-secondary);
border: 1px solid rgba(16, 185, 129, 0.3);
border-radius: 4px;
padding: 0.25rem 0.75rem;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 500;
}
.lang-btn:hover, .lang-btn.active {
color: var(--primary-green);
border-color: var(--primary-green);
}
.hero {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 6rem 2rem 2rem;
position: relative;
overflow: hidden;
}
.hero-content {
text-align: center;
max-width: 800px;
z-index: 2;
}
.hero h1 {
font-size: 3.5rem;
font-weight: 800;
margin-bottom: 1rem;
background: linear-gradient(to right, var(--primary-green), var(--secondary-green));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: glow 2s ease-in-out infinite alternate;
}
@keyframes glow {
from { text-shadow: 0 0 10px rgba(16, 185, 129, 0.5); }
to { text-shadow: 0 0 20px rgba(16, 185, 129, 0.8), 0 0 30px rgba(16, 185, 129, 0.6); }
}
.hero p {
font-size: 1.25rem;
color: var(--text-secondary);
margin-bottom: 2rem;
opacity: 0;
animation: fadeInUp 1s ease-out 0.5s forwards;
}
.screenshot {
width: 100%;
max-width: 800px;
border-radius: 12px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
margin: 2rem 0;
opacity: 0;
transform: translateY(30px);
animation: fadeInUp 1s ease-out 1s forwards;
border: 1px solid rgba(16, 185, 129, 0.3);
}
.features {
padding: 6rem 2rem;
background: rgba(30, 41, 59, 0.5);
}
.section-title {
text-align: center;
font-size: 2.5rem;
margin-bottom: 3rem;
background: linear-gradient(to right, var(--primary-green), var(--secondary-green));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
max-width: 1200px;
margin: 0 auto;
}
.feature-card {
background: rgba(30, 41, 59, 0.7);
border-radius: 12px;
padding: 2rem;
transition: all 0.3s ease;
border: 1px solid rgba(16, 185, 129, 0.2);
opacity: 0;
transform: translateY(30px);
}
.feature-card:hover {
transform: translateY(-10px);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
border-color: rgba(16, 185, 129, 0.5);
}
.feature-icon {
font-size: 2.5rem;
margin-bottom: 1rem;
color: var(--primary-green);
}
.feature-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
}
.installation {
padding: 6rem 2rem;
text-align: center;
}
.code-block {
background: rgba(15, 23, 42, 0.8);
border-radius: 8px;
padding: 1.5rem;
margin: 1rem 0;
text-align: left;
font-family: 'Monaco', 'Consolas', monospace;
font-size: 0.9rem;
border: 1px solid rgba(16, 185, 129, 0.3);
overflow-x: auto;
max-width: 600px;
margin: 1rem auto;
opacity: 0;
transform: translateY(30px);
}
.workflow {
padding: 6rem 2rem;
background: rgba(30, 41, 59, 0.5);
}
.steps {
max-width: 800px;
margin: 0 auto;
}
.step {
display: flex;
align-items: flex-start;
margin-bottom: 2rem;
opacity: 0;
transform: translateX(-30px);
}
.step-number {
background: var(--primary-green);
color: white;
width: 32px;
height: 32px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
margin-right: 1rem;
flex-shrink: 0;
margin-top: 0.25rem;
}
.step-content h3 {
margin-bottom: 0.5rem;
color: var(--primary-green-light);
}
.license {
padding: 6rem 2rem;
text-align: center;
}
.cta-button {
background: linear-gradient(135deg, var(--primary-green), var(--primary-green-dark));
color: white;
border: none;
padding: 1rem 2rem;
border-radius: 8px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
margin: 1rem 0;
box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.3);
}
.cta-button:hover {
transform: translateY(-2px);
box-shadow: 0 20px 25px -5px rgba(16, 185, 129, 0.4);
}
.footer {
background: rgba(15, 23, 42, 0.9);
padding: 3rem 2rem;
text-align: center;
border-top: 1px solid rgba(16, 185, 129, 0.2);
}
@keyframes fadeInUp {
to {
opacity: 1;
transform: translateY(0) translateX(0);
}
}
@media (max-width: 768px) {
.hero h1 {
font-size: 2.5rem;
}
.nav-links {
gap: 1rem; /* 在小屏幕上减小间距 */
/* 确保在非常小的屏幕上,语言切换器可以换行或调整 */
flex-wrap: wrap;
justify-content: center;
}
.section-title {
font-size: 2rem;
}
}
</style>
</head>
<body>
<div class="particles" id="particles"></div>
<header class="header">
<nav class="nav">
<div class="logo">
<span>🐍</span>
<span data-i18n="project_name">Nuitka-GUI-Packager</span>
</div>
<div class="nav-links">
<a href="#features" class="nav-link" data-i18n="nav_features">功能特性</a>
<a href="#installation" class="nav-link" data-i18n="nav_installation">安装使用</a>
<a href="#workflow" class="nav-link" data-i18n="nav_workflow">打包流程</a>
<a href="#license" class="nav-link" data-i18n="nav_license">许可证</a>
<div class="language-switcher">
<button class="lang-btn active" data-lang="zh">CN</button>
<button class="lang-btn" data-lang="en">EN</button>
</div>
</div>
</nav>
</header>
<section class="hero">
<div class="hero-content">
<h1 data-i18n="project_name">Nuitka-GUI-Packager</h1>
<p data-i18n="hero_description">一个基于 PySide6 开发的 Nuitka 图形化打包工具,简化 Python 应用程序的打包过程。</p>
<!-- 截图 src 将由 JS 根据语言更新 -->
<img id="screenshot-img" src="docs/images/screenshot_zh.png" alt="界面截图" class="screenshot" data-i18n-alt="screenshot_alt">
</div>
</section>
<section class="features" id="features">
<h2 class="section-title" data-i18n="features_title">主要功能</h2>
<div class="features-grid">
<div class="feature-card">
<div class="feature-icon">👁️</div>
<h3 class="feature-title" data-i18n="feature_visual_title">可视化配置</h3>
<p data-i18n="feature_visual_desc">通过直观的界面配置 Nuitka 打包参数</p>
</div>
<div class="feature-card">
<div class="feature-icon">📋</div>
<h3 class="feature-title" data-i18n="feature_tabs_title">多标签页管理</h3>
<p data-i18n="feature_tabs_desc">将复杂参数分类组织在 8 个标签页中</p>
</div>
<div class="feature-card">
<div class="feature-icon">⚡</div>
<h3 class="feature-title" data-i18n="feature_command_title">实时命令生成</h3>
<p data-i18n="feature_command_desc">根据用户选择自动生成 Nuitka 命令</p>
</div>
<div class="feature-card">
<div class="feature-icon">📊</div>
<h3 class="feature-title" data-i18n="feature_monitor_title">打包过程监控</h3>
<p data-i18n="feature_monitor_desc">实时显示打包日志和进度</p>
</div>
<div class="feature-card">
<div class="feature-icon">⚙️</div>
<h3 class="feature-title" data-i18n="feature_presets_title">常用预设</h3>
<p data-i18n="feature_presets_desc">内置常用选项的一键配置</p>
</div>
<div class="feature-card">
<div class="feature-icon">🔌</div>
<h3 class="feature-title" data-i18n="feature_plugins_title">插件支持</h3>
<p data-i18n="feature_plugins_desc">支持 PySide6, Tkinter 等常用插件</p>
</div>
</div>
</section>
<section class="installation" id="installation">
<h2 class="section-title" data-i18n="installation_title">使用说明</h2>
<div class="code-block">
<span data-i18n="code_clone_comment"># 克隆仓库</span><br>
git clone https://github.com/xiaoyingv/Nuitka-GUI-Packager.git<br>
cd Nuitka-GUI-Packager
</div>
<div class="code-block">
<span data-i18n="code_pip_comment"># 安装依赖(使用pip)</span><br>
pip install -r requirements.txt
</div>
<div class="code-block">
<span data-i18n="code_uv_comment"># 安装依赖(使用uv)</span><br>
uv pip install -r requirements.txt
</div>
<div class="code-block">
<span data-i18n="code_run_comment"># 运行程序</span><br>
<span data-i18n="run_command">python main_zh.py</span>
</div>
<a href="https://github.com/xiaoyingv/Nuitka-GUI-Packager" target="_blank" style="text-decoration: none;">
<button class="cta-button" data-i18n="button_experience">立即体验</button>
</a>
</section>
<section class="workflow" id="workflow">
<h2 class="section-title" data-i18n="workflow_title">打包流程</h2>
<div class="steps">
<div class="step">
<div class="step-number">1</div>
<div class="step-content">
<h3 data-i18n="step1_title">检查 Nuitka 已安装</h3>
<p data-i18n="step1_desc">请确保选择的环境 Nuitka 已经安装到运行环境。</p>
</div>
</div>
<div class="step">
<div class="step-number">2</div>
<div class="step-content">
<h3 data-i18n="step2_title">选择 Python 解释器</h3>
<p data-i18n="step2_desc">选择要打包文件python环境中的python解释器</p>
</div>
</div>
<div class="step">
<div class="step-number">3</div>
<div class="step-content">
<h3 data-i18n="step3_title">选择主文件</h3>
<p data-i18n="step3_desc">选择主文件选择要打包的程序文件入口文件</p>
</div>
</div>
<div class="step">
<div class="step-number">4</div>
<div class="step-content">
<h3 data-i18n="step4_title">选择图标文件(可选)</h3>
<p data-i18n="step4_desc">选择图标文件,例如:C:\Users\myapp\icon.ico</p>
</div>
</div>
<div class="step">
<div class="step-number">5</div>
<div class="step-content">
<h3 data-i18n="step5_title">选择输出目录</h3>
<p data-i18n="step5_desc">选择输出目录将保存打包后的可执行文件</p>
</div>
</div>
<div class="step">
<div class="step-number">6</div>
<div class="step-content">
<h3 data-i18n="step6_title">配置常用选项</h3>
<p data-i18n="step6_desc">你可以在标签页中选择常用选项,例如:是否使用standalone模式打包</p>
</div>
</div>
</div>
</section>
<section class="license" id="license">
<h2 class="section-title" data-i18n="license_title">许可证</h2>
<p>
<span data-i18n="license_desc_prefix">该项目遵循 </span>
<a href="https://opensource.org/licenses/MIT" style="color: var(--primary-green-light);" data-i18n="license_link_text">MIT License</a>
<span data-i18n="license_desc_suffix"> 许可证。</span>
</p>
<a href="https://github.com/xiaoyingv/Nuitka-GUI-Packager" target="_blank" style="text-decoration: none;">
<button class="cta-button" data-i18n="button_source">查看源码</button>
</a>
</section>
<footer class="footer">
<p data-i18n="footer_text">© 2025 Nuitka-GUI-Packager. 让 Python 打包变得更简单。</p>
</footer>
<script>
// 翻译资源
const resources = {
en: {
translation: {
"title": "Nuitka-GUI-Packager - Nuitka Graphical Packaging Tool",
"project_name": "Nuitka-GUI-Packager",
"hero_description": "A graphical packaging tool for Nuitka based on PySide6, simplifying the process of packaging Python applications.",
"screenshot_alt": "GUI Interface Screenshot",
"nav_features": "Features",
"nav_installation": "Installation",
"nav_workflow": "Workflow",
"nav_license": "License",
"features_title": "Key Features",
"feature_visual_title": "Visual Configuration",
"feature_visual_desc": "Configure Nuitka packaging parameters through an intuitive interface.",
"feature_tabs_title": "Multi-Tab Management",
"feature_tabs_desc": "Organize complex parameters across 8 tabs.",
"feature_command_title": "Real-time Command Generation",
"feature_command_desc": "Automatically generates Nuitka commands based on user selections.",
"feature_monitor_title": "Packaging Process Monitoring",
"feature_monitor_desc": "Displays packaging logs and progress in real-time.",
"feature_presets_title": "Common Presets",
"feature_presets_desc": "Built-in one-click configuration for common options.",
"feature_plugins_title": "Plugin Support",
"feature_plugins_desc": "Supports plugins like PySide6, Tkinter, etc.",
"installation_title": "Installation & Usage",
"code_clone_comment": "# Clone the repository",
"code_pip_comment": "# Install dependencies (using pip)",
"code_uv_comment": "# Install dependencies (using uv)",
"code_run_comment": "# Run the program",
"run_command": "python main.py", // 英文版运行命令
"button_experience": "Experience Now",
"workflow_title": "Packaging Workflow",
"step1_title": "Check Nuitka Installation",
"step1_desc": "Ensure Nuitka is installed in the selected Python environment.",
"step2_title": "Select Python Interpreter",
"step2_desc": "Choose the Python interpreter from the environment of the file to be packaged.",
"step3_title": "Select Main File",
"step3_desc": "Choose the main entry point file of the program to be packaged.",
"step4_title": "Select Icon File (Optional)",
"step4_desc": "Choose an icon file, e.g., C:\\Users\\myapp\\icon.ico",
"step5_title": "Select Output Directory",
"step5_desc": "Choose the directory where the packaged executable will be saved.",
"step6_title": "Configure Common Options",
"step6_desc": "Select common options in the tabs, e.g., whether to use standalone mode.",
"license_title": "License",
"license_desc_prefix": "This project is licensed under the ",
"license_link_text": "MIT License",
"license_desc_suffix": ".",
"button_source": "View Source Code",
"footer_text": "© 2025 Nuitka-GUI-Packager. Making Python packaging easier."
}
},
zh: {
translation: {
"title": "Nuitka-GUI-Packager - Nuitka 图形化打包工具",
"project_name": "Nuitka-GUI-Packager",
"hero_description": "一个基于 PySide6 开发的 Nuitka 图形化打包工具,简化 Python 应用程序的打包过程。",
"screenshot_alt": "界面截图",
"nav_features": "功能特性",
"nav_installation": "安装使用",
"nav_workflow": "打包流程",
"nav_license": "许可证",
"features_title": "主要功能",
"feature_visual_title": "可视化配置",
"feature_visual_desc": "通过直观的界面配置 Nuitka 打包参数",
"feature_tabs_title": "多标签页管理",
"feature_tabs_desc": "将复杂参数分类组织在 8 个标签页中",
"feature_command_title": "实时命令生成",
"feature_command_desc": "根据用户选择自动生成 Nuitka 命令",
"feature_monitor_title": "打包过程监控",
"feature_monitor_desc": "实时显示打包日志和进度",
"feature_presets_title": "常用预设",
"feature_presets_desc": "内置常用选项的一键配置",
"feature_plugins_title": "插件支持",
"feature_plugins_desc": "支持 PySide6, Tkinter 等常用插件",
"installation_title": "使用说明",
"code_clone_comment": "# 克隆仓库",
"code_pip_comment": "# 安装依赖(使用pip)",
"code_uv_comment": "# 安装依赖(使用uv)",
"code_run_comment": "# 运行程序",
"run_command": "python main_zh.py", // 中文版运行命令
"button_experience": "立即体验",
"workflow_title": "打包流程",
"step1_title": "检查 Nuitka 已安装",
"step1_desc": "请确保选择的环境 Nuitka 已经安装到运行环境。",
"step2_title": "选择 Python 解释器",
"step2_desc": "选择要打包文件python环境中的python解释器",
"step3_title": "选择主文件",
"step3_desc": "选择主文件选择要打包的程序文件入口文件",
"step4_title": "选择图标文件(可选)",
"step4_desc": "选择图标文件,例如:C:\\Users\\myapp\\icon.ico",
"step5_title": "选择输出目录",
"step5_desc": "选择输出目录将保存打包后的可执行文件",
"step6_title": "配置常用选项",
"step6_desc": "你可以在标签页中选择常用选项,例如:是否使用standalone模式打包",
"license_title": "许可证",
"license_desc_prefix": "该项目遵循 ",
"license_link_text": "MIT License",
"license_desc_suffix": " 许可证。",
"button_source": "查看源码",
"footer_text": "© 2025 Nuitka-GUI-Packager. 让 Python 打包变得更简单。"
}
}
};
// 语言到截图路径的映射
const screenshotPaths = {
'zh': 'docs/images/screenshot_zh.png',
'en': 'docs/images/sc_en.png'
};
// 根据当前语言更新页面内容
function updateContent() {
// 更新文本内容
document.querySelectorAll('[data-i18n]').forEach(element => {
const key = element.getAttribute('data-i18n');
// 特殊处理图片的 alt 属性
if (element.tagName === 'IMG' && element.hasAttribute('data-i18n-alt')) {
const altKey = element.getAttribute('data-i18n-alt');
element.alt = i18next.t(altKey);
} else {
// 避免覆盖包含其他元素(如链接)的父元素的内部HTML
if (element.children.length === 0) {
element.textContent = i18next.t(key);
}
}
});
// 更新页面标题
document.title = i18next.t('title');
// 更新截图图片的 src 和 alt
const screenshotImg = document.getElementById('screenshot-img');
if (screenshotImg) {
screenshotImg.src = screenshotPaths[i18next.language] || screenshotPaths['zh']; // 回退到中文
// 如果有 data-i18n-alt,则更新 alt 文本
if (screenshotImg.hasAttribute('data-i18n-alt')) {
const altKey = screenshotImg.getAttribute('data-i18n-alt');
screenshotImg.alt = i18next.t(altKey);
}
// 重新触发动画以确保切换时有淡入效果
screenshotImg.style.animation = 'none';
setTimeout(() => {
screenshotImg.style.animation = 'fadeInUp 1s ease-out 1s forwards';
}, 10);
}
// 更新语言切换按钮的激活状态
document.querySelectorAll('.lang-btn').forEach(btn => {
btn.classList.remove('active');
if (btn.getAttribute('data-lang') === i18next.language) {
btn.classList.add('active');
}
});
// 内容更新后重新初始化动画和滚动监听
setTimeout(() => {
// 重新运行动画(针对英雄文本)
const heroText = document.querySelector('.hero p');
if (heroText) {
heroText.style.animation = 'none';
setTimeout(() => {
heroText.style.animation = 'fadeInUp 1s ease-out 0.5s forwards';
}, 10);
}
// 重新绑定平滑滚动(以防万一)
smoothScroll();
// 重新检查滚动动画
animateOnScroll();
}, 100); // 短暂延迟以确保 DOM 更新完成
}
// 创建粒子效果
function createParticles() {
const particlesContainer = document.getElementById('particles');
particlesContainer.innerHTML = ''; // 清除现有粒子
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
const size = Math.random() * 4 + 1;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
particle.style.left = `${Math.random() * 100}%`;
particle.style.top = `${Math.random() * 100}%`;
particle.style.animationDelay = `${Math.random() * 6}s`;
particlesContainer.appendChild(particle);
}
}
// 滚动动画
function animateOnScroll() {
const elements = document.querySelectorAll('.feature-card, .code-block, .step');
const windowHeight = window.innerHeight;
elements.forEach(element => {
const elementTop = element.getBoundingClientRect().top;
if (elementTop < windowHeight * 0.8) {
// 确保动画只播放一次
if (!element.style.animation || element.style.animation.includes('none')) {
element.style.animation = 'fadeInUp 0.8s ease-out forwards';
}
}
});
}
// 平滑滚动
function smoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.removeEventListener('click', handleScroll);
anchor.addEventListener('click', handleScroll);
});
}
function handleScroll(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const target = document.querySelector(targetId);
if (target) {
// 调整滚动偏移量以适应固定头部
const headerHeight = document.querySelector('.header').offsetHeight;
const targetPosition = target.offsetTop - headerHeight - 10; // 添加一点额外空间
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
}
// 初始化应用
document.addEventListener('DOMContentLoaded', () => {
// 检测浏览器语言或默认为 'zh'
const userLang = navigator.language || navigator.userLanguage;
const initialLang = resources[userLang] ? userLang : (resources[userLang.split('-')[0]] ? userLang.split('-')[0] : 'zh');
// 初始化 i18next
i18next.init({
lng: initialLang,
fallbackLng: 'zh', // 如果找不到键,则回退到中文
resources: resources,
interpolation: {
escapeValue: false // React 已经处理了 XSS
}
}).then(() => {
// 初始内容更新
updateContent();
// 创建初始粒子
createParticles();
// 设置语言切换器按钮
document.querySelectorAll('.lang-btn').forEach(button => {
button.addEventListener('click', () => {
const lang = button.getAttribute('data-lang');
i18next.changeLanguage(lang).then(() => {
updateContent(); // 语言更改后更新内容
createParticles(); // 重新创建粒子以获得视觉刷新
}).catch(err => {
console.error('Error changing language:', err);
});
});
});
// 设置初始激活按钮状态(HTML中已设置,但再次确认)
document.querySelector(`.lang-btn[data-lang="${initialLang}"]`).classList.add('active');
// 设置平滑滚动
smoothScroll();
// 设置滚动监听器以触发动画
window.addEventListener('scroll', animateOnScroll);
// 初始检查视口中的元素
animateOnScroll();
}).catch(err => {
console.error('Error initializing i18next:', err);
// 回退:如果 i18next 初始化失败,则显示默认(中文)内容
updateContent();
createParticles();
smoothScroll();
window.addEventListener('scroll', animateOnScroll);
animateOnScroll();
});
});
</script>
</body>
</html>