-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
189 lines (168 loc) · 7.41 KB
/
Copy pathscript.js
File metadata and controls
189 lines (168 loc) · 7.41 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
// Navbar toggle functionality
const navToggle = document.querySelector('.nav-toggle');
const navMenu = document.querySelector('.nav-menu');
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
navToggle.classList.toggle('active');
});
// Close menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
navMenu.classList.remove('active');
navToggle.classList.remove('active');
}));
// Sticky navbar
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Form submission
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get form values
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const subject = document.getElementById('subject').value;
const message = document.getElementById('message').value;
// In a real application, you would send this data to a server
// For this frontend-only implementation, we'll just show an alert
alert(`Thank you for your message, ${name}! We'll get back to you soon.`);
// Reset form
contactForm.reset();
});
}
// Sample blog post data
const blogPosts = [
{
id: 1,
title: "The Future of Web Design",
excerpt: "Exploring the latest trends and technologies shaping the future of web design in 2023 and beyond.",
image: "https://images.unsplash.com/photo-1547661362-0a7d47c0a612?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80",
date: "May 10, 2023",
category: "Design"
},
{
id: 2,
title: "JavaScript Frameworks Comparison",
excerpt: "A detailed comparison of the most popular JavaScript frameworks and when to use each one.",
image: "https://images.unsplash.com/photo-1555066931-4365d14bab8c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80",
date: "May 5, 2023",
category: "Development"
},
{
id: 3,
title: "Building Accessible Websites",
excerpt: "Learn how to create websites that are accessible to all users, including those with disabilities.",
image: "https://images.unsplash.com/photo-1551650975-835a074eee33?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80",
date: "April 28, 2023",
category: "Accessibility"
},
{
id: 4,
title: "Optimizing Website Performance",
excerpt: "Practical tips and techniques to improve your website's loading speed and overall performance.",
image: "https://images.unsplash.com/photo-1553877522-43269d4ea984?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80",
date: "April 20, 2023",
category: "Performance"
},
{
id: 5,
title: "The Art of CSS Grid",
excerpt: "Mastering CSS Grid layout system to create complex and responsive web designs.",
image: "https://images.unsplash.com/photo-1633356122102-3fe601e01bd6?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80",
date: "April 15, 2023",
category: "CSS"
},
{
id: 6,
title: "Introduction to Web Accessibility",
excerpt: "Understanding the basics of web accessibility and why it matters for inclusive design.",
image: "https://images.unsplash.com/photo-1551650992-ee4fd47a0b5d?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80",
date: "April 10, 2023",
category: "Accessibility"
}
];
// Function to generate blog post cards
function generatePostCard(post) {
return `
<div class="post-card">
<div class="post-image">
<img src="${post.image}" alt="${post.title}">
</div>
<div class="post-content">
<span class="post-category">${post.category}</span>
<h3>${post.title}</h3>
<p class="post-excerpt">${post.excerpt}</p>
<div class="post-meta">
<span class="post-date">${post.date}</span>
</div>
<a href="post.html" class="read-more">Read More</a>
</div>
</div>
`;
}
// Function to display featured posts on home page
function displayFeaturedPosts() {
const featuredPostsContainer = document.querySelector('.featured-posts .posts-grid');
if (featuredPostsContainer) {
// Display first 3 posts as featured
const featuredPosts = blogPosts.slice(0, 3);
featuredPostsContainer.innerHTML = featuredPosts.map(generatePostCard).join('');
}
}
// Function to display all blog posts on blog page
function displayAllPosts() {
const blogPostsContainer = document.querySelector('.blog-posts .posts-grid');
if (blogPostsContainer) {
blogPostsContainer.innerHTML = blogPosts.map(generatePostCard).join('');
}
}
// Function to display related posts on single post page
function displayRelatedPosts() {
const relatedPostsContainer = document.querySelector('.related-posts .posts-grid');
if (relatedPostsContainer) {
// Display last 3 posts as related
const relatedPosts = blogPosts.slice(-3);
relatedPostsContainer.innerHTML = relatedPosts.map(generatePostCard).join('');
}
}
// Initialize the page
document.addEventListener('DOMContentLoaded', () => {
// Display posts based on current page
if (document.querySelector('.featured-posts')) {
displayFeaturedPosts();
}
if (document.querySelector('.blog-posts')) {
displayAllPosts();
}
if (document.querySelector('.related-posts')) {
displayRelatedPosts();
}
// Add animation to elements when they come into view
const animateOnScroll = function() {
const elements = document.querySelectorAll('.post-card, .team-member, .about-text, .contact-info');
elements.forEach(element => {
const elementPosition = element.getBoundingClientRect().top;
const screenPosition = window.innerHeight / 1.3;
if (elementPosition < screenPosition) {
element.style.opacity = "1";
element.style.transform = "translateY(0)";
}
});
};
// Set initial state for animated elements
document.querySelectorAll('.post-card, .team-member, .about-text, .contact-info').forEach(element => {
element.style.opacity = "0";
element.style.transform = "translateY(20px)";
element.style.transition = "opacity 0.5s ease, transform 0.5s ease";
});
// Listen for scroll events
window.addEventListener('scroll', animateOnScroll);
// Trigger once on page load
animateOnScroll();
});