-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
78 lines (66 loc) · 2.33 KB
/
index.js
File metadata and controls
78 lines (66 loc) · 2.33 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
// -----------------------------
// Ticket Form Validation & Submit
// -----------------------------
const ticketForm = document.getElementById('ticketForm');
ticketForm.addEventListener('submit', function(e){
e.preventDefault();
const name = document.getElementById('ticketName').value.trim();
const email = document.getElementById('ticketEmail').value.trim();
const type = document.getElementById('ticketType').value;
const desc = document.getElementById('ticketDesc').value.trim();
if(!name || !email || !type || !desc){
showToast("Please fill all fields!", "error");
return;
}
// Simulate form submission
showToast("Ticket submitted successfully!", "success");
ticketForm.reset();
});
// -----------------------------
// Toast Notification Function
// -----------------------------
function showToast(message, type){
let toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add('show');
}, 100);
setTimeout(() => {
toast.classList.remove('show');
setTimeout(()=> toast.remove(), 300);
}, 3000);
}
// -----------------------------
// Smooth Scroll + Section Reveal
// -----------------------------
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('nav ul li a');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
if(window.pageYOffset >= sectionTop) current = section.getAttribute('id');
// Reveal animation
if(window.pageYOffset + window.innerHeight > section.offsetTop + 100){
section.classList.add('visible');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if(link.getAttribute('href') === '#' + current){
link.classList.add('active');
}
});
});
// -----------------------------
// Smooth Scroll on Nav Click
// -----------------------------
navLinks.forEach(link => {
link.addEventListener('click', (e)=>{
e.preventDefault();
const target = document.querySelector(link.getAttribute('href'));
target.scrollIntoView({behavior:'smooth'});
});
});