Skip to content

Commit 41b8a89

Browse files
authored
Merge pull request #1 from techdiwas/copilot/improve-website-efficiency
Optimize website performance with throttled scroll handlers and async font loading
2 parents ed98820 + fbb8f5a commit 41b8a89

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Diwas | Portfolio</title>
7+
<link rel="preconnect" href="https://fonts.googleapis.com">
8+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap" rel="stylesheet">
710
<link rel="stylesheet" href="style.css" />
811
</head>
912
<body>
@@ -74,6 +77,6 @@ <h2>Contact</h2>
7477
<p>&copy; 2025 Diwas. All rights reserved.</p>
7578
</footer>
7679

77-
<script src="script.js"></script>
80+
<script src="script.js" defer></script>
7881
</body>
7982
</html>

script.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1-
// Simple scroll fade-in
2-
window.addEventListener('scroll', () => {
3-
document.querySelectorAll('section').forEach(section => {
1+
// Throttle function for better performance
2+
function throttle(func, delay) {
3+
let lastCall = 0;
4+
return function(...args) {
5+
const now = Date.now();
6+
if (now - lastCall >= delay) {
7+
lastCall = now;
8+
func.apply(this, args);
9+
}
10+
};
11+
}
12+
13+
// Simple scroll fade-in with throttling
14+
const handleScroll = throttle(() => {
15+
const sections = document.querySelectorAll('section');
16+
const windowHeight = window.innerHeight;
17+
18+
sections.forEach(section => {
419
const rect = section.getBoundingClientRect();
5-
if(rect.top < window.innerHeight - 50) {
20+
if(rect.top < windowHeight - 50) {
621
section.classList.add('visible');
722
}
823
});
9-
});
24+
}, 100);
25+
26+
window.addEventListener('scroll', handleScroll, { passive: true });
27+
// Trigger on load to handle initial viewport
28+
handleScroll();

style.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ nav.scroll-header ul li a:hover {
128128
section {
129129
padding: 100px 20px;
130130
text-align: center;
131+
opacity: 0;
132+
transform: translateY(20px);
133+
transition: opacity 0.6s ease, transform 0.6s ease;
134+
}
135+
136+
section.visible {
137+
opacity: 1;
138+
transform: translateY(0);
131139
}
132140

133141
#projects .project-list {
@@ -182,11 +190,11 @@ footer {
182190
padding: 10px;
183191
background-color: #111;
184192
border-bottom: 1px solid #333;
185-
scrollbar-width: none; /* Firefox */
193+
scrollbar-width: none;
186194
}
187195

188196
.scrollable-top::-webkit-scrollbar {
189-
display: none; /* Chrome, Safari */
197+
display: none;
190198
}
191199

192200
.scroll-item {

0 commit comments

Comments
 (0)