-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
159 lines (135 loc) · 5.19 KB
/
script.js
File metadata and controls
159 lines (135 loc) · 5.19 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
// ============================================
// Dark Mode Toggle
// ============================================
const darkModeToggle = document.getElementById('darkModeToggle');
const htmlElement = document.documentElement;
// Check for saved theme preference or use system preference
const getSavedTheme = () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
return savedTheme;
}
// Check system preference
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
};
// Set initial theme
const currentTheme = getSavedTheme();
htmlElement.setAttribute('data-theme', currentTheme);
// Dark mode toggle functionality
if (darkModeToggle) {
darkModeToggle.addEventListener('click', () => {
const currentTheme = htmlElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
htmlElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
}
// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
// Only auto-switch if user hasn't manually set a preference
if (!localStorage.getItem('theme')) {
const newTheme = e.matches ? 'dark' : 'light';
htmlElement.setAttribute('data-theme', newTheme);
}
});
// ============================================
// Mobile Menu Toggle
// ============================================
function setupMobileMenu() {
const menuButton = document.querySelector('.mobile-menu-button');
const navMenu = document.querySelector('.nav-menu');
if (menuButton && navMenu) {
menuButton.addEventListener('click', () => {
navMenu.classList.toggle('active');
menuButton.classList.toggle('active');
// Update aria-expanded
const isExpanded = menuButton.classList.contains('active');
menuButton.setAttribute('aria-expanded', isExpanded);
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!menuButton.contains(e.target) && !navMenu.contains(e.target)) {
navMenu.classList.remove('active');
menuButton.classList.remove('active');
menuButton.setAttribute('aria-expanded', 'false');
}
});
// Close menu when clicking a link
navMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
menuButton.classList.remove('active');
menuButton.setAttribute('aria-expanded', 'false');
});
});
}
}
// Initialize mobile menu
document.addEventListener('DOMContentLoaded', setupMobileMenu);
// ============================================
// Scroll Animations
// ============================================
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('active');
}
});
}, observerOptions);
// Observe all elements that should animate on scroll
document.addEventListener('DOMContentLoaded', () => {
const revealElements = document.querySelectorAll('.feature-card, .step-card, .timeline-item, .catalog-card, .arch-box');
revealElements.forEach(el => {
el.classList.add('reveal');
observer.observe(el);
});
});
// ============================================
// Header Scroll Effect
// ============================================
let lastScroll = 0;
const header = document.querySelector('.header');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
lastScroll = currentScroll;
});
// ============================================
// Smooth Scroll for Anchor Links
// ============================================
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
// Don't prevent default for empty hash
if (href === '#') return;
e.preventDefault();
const target = document.querySelector(href);
if (target) {
const headerOffset = 80;
const elementPosition = target.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
// ============================================
// Console Message
// ============================================
console.log(
'%c easytocloud ',
'background: #D94A1A; color: white; font-size: 20px; padding: 10px; border-radius: 5px;',
'\n\nTools for AWS developers\n' +
'GitHub: https://github.com/easytocloud\n' +
'© 2025 easytocloud\n'
);