-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
141 lines (125 loc) · 4.72 KB
/
basic.js
File metadata and controls
141 lines (125 loc) · 4.72 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
const projects = [
{
id: 1,
title: "Responsive Portfolio Website",
category: "html css",
image: "https://images.unsplash.com/photo-1507238691740-187a5b1d37b8?auto=format&fit=crop&q=80&w=300",
description: "A responsive portfolio website template using HTML and CSS."
},
{
id: 2,
title: "Interactive To-Do List",
category: "javascript",
image: "https://images.unsplash.com/photo-1555421689-d68471e189f2?auto=format&fit=crop&q=80&w=300",
description: "A dynamic to-do list application using JavaScript."
},
{
id: 3,
title: "Weather Dashboard",
category: "react",
image: "https://images.unsplash.com/photo-1530908295418-a12e326966ba?auto=format&fit=crop&q=80&w=300",
description: "A weather dashboard built with React.js and OpenWeather API."
},
{
id: 4,
title: "Data Visualization App",
category: "python",
image: "https://images.unsplash.com/photo-1551288049-bebda4e38f71?auto=format&fit=crop&q=80&w=300",
description: "A data visualization tool built with Python and Matplotlib."
},
{
id: 5,
title: "E-Commerce Application",
category: "java",
image: "https://images.unsplash.com/photo-1563013544-824ae1b704d3?auto=format&fit=crop&q=80&w=300",
description: "A simple e-commerce application built with Java and Spring Boot."
},
{
id: 6,
title: "Animated Navigation Menu",
category: "css javascript",
image: "https://images.unsplash.com/photo-1517180102446-f3ece451e9d8?auto=format&fit=crop&q=80&w=300",
description: "A creative animated navigation menu using CSS and JavaScript."
}
];
// DOM Elements
const header = document.getElementById('header');
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const navMenu = document.getElementById('nav-menu');
const projectsGrid = document.getElementById('projects-grid');
const filterBtns = document.querySelectorAll('.filter-btn');
// Handle Scroll
window.addEventListener('scroll', () => {
if (window.scrollY > 80) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// Mobile Menu Toggle
mobileMenuBtn.addEventListener('click', () => {
navMenu.classList.toggle('active');
mobileMenuBtn.innerHTML = navMenu.classList.contains('active') ? '<i class="fas fa-times"></i>' : '<i class="fas fa-bars"></i>';
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
mobileMenuBtn.innerHTML = '<i class="fas fa-bars"></i>';
});
});
// Filter Projects
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Remove active class from all buttons
filterBtns.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
btn.classList.add('active');
// Get filter value
const filter = btn.getAttribute('data-filter');
// Filter projects
displayProjects(filter);
});
});
// Display Projects
function displayProjects(filter = 'all') {
projectsGrid.innerHTML = '';
projects.forEach(project => {
if (filter === 'all' || project.category.includes(filter)) {
const projectCard = document.createElement('div');
projectCard.className = 'project-card';
projectCard.innerHTML = `
<div class="project-image">
<img src="${project.image}" alt="${project.title}">
</div>
<div class="project-info">
<div class="project-category">${project.category}</div>
<h3 class="project-title">${project.title}</h3>
<p class="project-description">${project.description}</p>
<a href="#" class="btn btn-secondary">View Project</a>
</div>
`;
projectsGrid.appendChild(projectCard);
}
});
}
// Initial load
displayProjects();
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});