forked from KusionStack/kusion-landing-page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
181 lines (157 loc) · 5.81 KB
/
main.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
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
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Navbar scroll effect
const navbar = document.querySelector('.navbar');
navbar.style.transform = 'translateY(0)'; // Always show navbar
// Typewriter animation
function typeWriter(element, text, speed = 20) {
const typingElement = element.querySelector('.typing');
const cursorElement = element.querySelector('.cursor');
let i = 0;
typingElement.textContent = '';
element.style.opacity = '1';
function type() {
if (i < text.length) {
typingElement.textContent = text.substring(0, i + 1);
// Move cursor to the end of the typed text
typingElement.appendChild(cursorElement);
i++;
setTimeout(type, speed);
}
}
type();
}
// Handle newsletter subscription
function handleSubscribe(event) {
event.preventDefault();
const form = event.target;
const button = form.querySelector('button');
const email = form.querySelector('input[type="email"]').value;
// Here you would typically send the email to your backend
console.log('Subscribing email:', email);
// Show success state
button.textContent = 'Subscribed!';
button.classList.add('subscribed');
form.reset();
setTimeout(() => {
button.textContent = '';
button.classList.remove('subscribed');
}, 2000);
return false;
}
// Copy code to clipboard
function copyCode(elementId) {
const codeElement = document.getElementById(elementId);
if (!codeElement) return;
const text = codeElement.textContent;
const button = codeElement.closest('.code-block').querySelector('.copy-button');
const icon = button.querySelector('i');
navigator.clipboard.writeText(text).then(() => {
// Visual feedback
icon.classList.remove('fa-copy');
icon.classList.add('fa-check');
// Reset after 2 seconds
setTimeout(() => {
icon.classList.remove('fa-check');
icon.classList.add('fa-copy');
}, 2000);
}).catch(err => {
console.error('Failed to copy text: ', err);
// Visual feedback for error
icon.classList.remove('fa-copy');
icon.classList.add('fa-times');
setTimeout(() => {
icon.classList.remove('fa-times');
icon.classList.add('fa-copy');
}, 2000);
});
}
// Initialize animations when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
// Add animation class to features on scroll
const features = document.querySelectorAll('.feature-card');
const observer = new IntersectionObserver(
(entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
},
{ threshold: 0.1 }
);
features.forEach(feature => {
feature.style.opacity = '0';
feature.style.transform = 'translateY(20px)';
feature.style.transition = 'all 0.6s ease-out';
observer.observe(feature);
});
// Initialize typewriter
const subtitle = document.querySelector('.typewriter');
if (subtitle) {
const text = "Kusion is an open-source tool that simplifies the management of infrastructure and Kubernetes resources into a single and collaborative workflow.";
typeWriter(subtitle, text);
}
// Scroll animation for use case cards
const observeElements = () => {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
// Once animated, no need to observe anymore
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.2,
rootMargin: '50px'
});
const cards = document.querySelectorAll('.use-case-card');
cards.forEach(card => {
observer.observe(card);
});
};
setTimeout(observeElements, 100); // Small delay to ensure DOM is fully ready
// Mobile menu toggle
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
const navLinks = document.querySelector('.nav-links');
if (mobileMenuBtn && navLinks) {
mobileMenuBtn.addEventListener('click', function() {
navLinks.classList.toggle('active');
// Toggle icon
const icon = this.querySelector('i');
if (icon) {
if (navLinks.classList.contains('active')) {
icon.classList.remove('fa-bars');
icon.classList.add('fa-times');
} else {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
}
});
// Close menu when clicking outside
document.addEventListener('click', function(event) {
if (!mobileMenuBtn.contains(event.target) && !navLinks.contains(event.target)) {
navLinks.classList.remove('active');
const icon = mobileMenuBtn.querySelector('i');
if (icon) {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
}
});
}
});