-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
114 lines (94 loc) · 3.84 KB
/
Copy pathmain.js
File metadata and controls
114 lines (94 loc) · 3.84 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
document.addEventListener('DOMContentLoaded', () => {
const navLinks = document.querySelectorAll('.main-nav a');
const projectItems = document.querySelectorAll('.main-content .project-item');
let currentCategory = 'all'; // 跟踪当前显示的分类
// 为每个导航链接添加点击事件
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const category = e.target.getAttribute('href').replace('#', '');
// 判断是否重新点击相同的分类
if (currentCategory === category) {
// 如果是,显示所有项目
projectItems.forEach(item => {
item.style.display = 'block';
});
currentCategory = 'all'; // 重置当前分类
} else {
// 否则,仅显示该分类的项目
projectItems.forEach(item => {
if (item.getAttribute('data-category') === category) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
currentCategory = category; // 更新当前分类
}
});
});
});
// document.addEventListener('DOMContentLoaded', () => {
// const projectItems = document.querySelectorAll('.project-item');
// projectItems.forEach(item => {
// // 生成随机宽度和高度
// const randomWidth = Math.floor(Math.random() * 3) + 1; // 生成1到3之间的随机数
// const randomHeight = 150 + Math.floor(Math.random() * 3) * 50; // 生成150到300之间的随机高度
// // 根据生成的随机数设置项目的宽度和高度
// item.style.flex = `0 0 calc(${randomWidth * 33.333}% - 16px)`;
// item.style.height = `${randomHeight}px`;
// });
// });
// Initialize a flag to keep track of whether non-about blocks are hidden
let areNonAboutBlocksHidden = false;
function showOnlyAbout() {
if (!areNonAboutBlocksHidden) {
// Hide all blocks that are not 'about'
document.querySelectorAll('.project-item').forEach(item => {
if (!item.classList.contains('about')) {
item.style.display = 'none';
}
});
// Update the flag
areNonAboutBlocksHidden = true;
} else {
// Show all blocks
document.querySelectorAll('.project-item').forEach(item => {
item.style.display = 'block';
});
// Update the flag
areNonAboutBlocksHidden = false;
}
}
// Add click event listener to each 'about' block
document.querySelectorAll('.about').forEach(item => {
item.addEventListener('click', showOnlyAbout);
});
document.querySelectorAll('.project-item.cdp, .project-item.architecture').forEach(item => {
item.addEventListener('click', function() {
// Logic for expanding the project item
this.classList.toggle('expanded'); // This toggles the expanded class on and off
const detail = this.querySelector('.project-detail');
if (this.classList.contains('expanded')) {
detail.style.display = 'block'; // Shows the project detail
} else {
detail.style.display = 'none'; // Hides the project detail
}
});
});
// document.querySelectorAll('.project-item.cdp, .project-item.architecture').forEach(item => {
// item.addEventListener('click', function() {
// // Toggles the expanded class on and off
// this.classList.toggle('expanded');
// });
// });
function toggleSidebar() {
var sidebar = document.getElementById("mySidebar");
var content = document.getElementById("mainContent");
sidebar.classList.toggle('active');
content.classList.toggle('shift');
}
function toggleSidebar() {
var sidebar = document.getElementById("mySidebar");
sidebar.classList.toggle('active');
}