forked from Lakshminair9746/eduplatform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (74 loc) · 3.09 KB
/
script.js
File metadata and controls
84 lines (74 loc) · 3.09 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
document.addEventListener('DOMContentLoaded', function() {
// Smooth scrolling for "Explore Courses" button and internal links
const exploreBtn = document.getElementById('exploreCoursesBtn');
const courseSection = document.querySelector('.featured-courses');
if (exploreBtn && courseSection) {
exploreBtn.addEventListener('click', function(e) {
e.preventDefault();
courseSection.scrollIntoView({
behavior: 'smooth'
});
});
}
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Active link highlighting for navigation (THIS WAS MISSING BEFORE!)
const currentLocation = location.href;
const navLinks = document.querySelectorAll('nav ul li a');
navLinks.forEach(link => {
if (link.href === currentLocation) {
link.classList.add('active');
}
});
// Simple animation/interaction for featured courses (optional, for later) (THIS WAS ALSO MISSING BEFORE!)
const courseCards = document.querySelectorAll('.course-card');
if (courseCards.length > 0) {
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 // Trigger when 10% of the item is visible
});
courseCards.forEach((card, index) => {
card.style.opacity = '0'; // Start invisible
card.style.transform = 'translateY(20px)'; // Start slightly below
card.style.transition = `opacity 0.6s ease-out ${index * 0.1}s, transform 0.6s ease-out ${index * 0.1}s`; // Add staggered transition
observer.observe(card);
});
}
// Update copyright year dynamically
const currentYearSpan = document.getElementById('current-year');
if (currentYearSpan) {
currentYearSpan.textContent = new Date().getFullYear();
}
const backToTopBtn = document.getElementById('backToTopBtn');
// Show/hide the button based on scroll position
window.addEventListener('scroll', function() {
if (window.scrollY > 300) { // Show button after scrolling 300px
backToTopBtn.style.display = 'block';
} else {
backToTopBtn.style.display = 'none';
}if (window.scrollY > 50) { // After scrolling 50px
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// Smooth scroll to top when button is clicked
backToTopBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
});