-
Notifications
You must be signed in to change notification settings - Fork 52
/
script.js
152 lines (126 loc) · 5.16 KB
/
script.js
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
fetch('./config.json').then(res => res.json()).then(data => {
const config = data;
const customCursor = document.createElement('div');
customCursor.classList.add('custom-cursor');
document.body.appendChild(customCursor);
const cursor = document.querySelector('.custom-cursor');
// Update cursor position
document.addEventListener('mousemove', (e) => {
cursor.style.top = `${e.clientY}px`;
cursor.style.left = `${e.clientX}px`;
});
// Apply hover effects to links and buttons
document.querySelectorAll('a, button, input[type=text], textarea').forEach((el) => {
var tempBgColor, tempColor;
el.addEventListener('mouseenter', () => {
const rect = el.getBoundingClientRect();
tempBgColor = el.style.backgroundColor;
tempColor = el.style.color;
if (el.attributes.type?.value == 'text') {
cursor.style.width = '2px';
cursor.style.height = `${rect.height - 10}px`;
cursor.style.backgroundColor = 'black';
}
else if (el.tagName == 'TEXTAREA') {
cursor.style.width = '2px';
cursor.style.height = '20px'; `${config.link.shadow.xoffset} ${config.link.shadow.yoffset} ${config.link.shadow.blurRadius} ${config.link.shadow.color}`
}
else {
cursor.style.width = `${rect.width}px`;
cursor.style.height = `${rect.height}px`;
if (el.tagName == 'A') {
el.style.textShadow = `${config.link.shadow.xoffset} ${config.link.shadow.yoffset} ${config.link.shadow.blurRadius} ${config.link.shadow.color}`;
el.style.color = config.link.onHoverColor;
}
else {
el.style.boxShadow = `${config.button.shadow.xoffset} ${config.button.shadow.yoffset} ${config.button.shadow.blurRadius} ${config.button.shadow.spread} ${config.button.shadow.color}`;
el.style.color = config.button.onHoverColor;
el.style.backgroundColor = config.button.onHoverBgColor;
}
el.style.transition = 'all 0.2s ease-out';
el.style.scale = '1.1';
cursor.style.backgroundColor = 'transparent';
cursor.style.border = '1px solid transparent';
}
cursor.style.borderRadius = `${Math.min(rect.height / 2, 12)}px`;
});
el.addEventListener('mouseleave', () => {
el.style.scale = '1';
if (el.tagName == 'A') {
el.style.textShadow = 'none';
}
else {
el.style.boxShadow = 'none';
}
el.style.color = tempColor;
el.style.backgroundColor = tempBgColor;
cursor.style.width = '30px';
cursor.style.height = '30px';
cursor.style.borderRadius = '50%';
cursor.style.backgroundColor = 'rgba(0, 0, 0, 0.4)';
cursor.style.border = '1px solid white';
});
});
}
);
// Get the button
let backToTopBtn = document.getElementById("backToTopBtn");
// Show the button when the user scrolls down 20px from the top of the document
window.onscroll = function() {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
backToTopBtn.style.display = "block"; // Show karta h
} else {
backToTopBtn.style.display = "none"; // Hide
}
}
// When the user clicks the button, the page scroll to the top
backToTopBtn.onclick = function() {
scrollToTop();
};
function scrollToTop() {
const scrollStep = window.scrollY / 20;
const scrollAnimation = () => {
if (window.scrollY > 0) {
window.scrollBy(0, -scrollStep);
requestAnimationFrame(scrollAnimation);
}
};
requestAnimationFrame(scrollAnimation);
}
window.onscroll = function() {
updateScrollIndicator();
};
function updateScrollIndicator() {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
const scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrollPercentage = (scrollTop / scrollHeight) * 100;
document.getElementById("scrollIndicator").style.width = scrollPercentage + "%";
}
let currentSlide = 0;
const slides = document.querySelectorAll('.carousel-slide');
function showSlide(index) {
// Hide all slides
slides.forEach(slide => slide.classList.remove('active'));
// Set the new active slide
slides[index].classList.add('active');
}
function moveSlide(direction) {
// Update currentSlide based on direction
currentSlide += direction;
// Loop around if at the start or end
if (currentSlide < 0) {
currentSlide = slides.length - 1;
} else if (currentSlide >= slides.length) {
currentSlide = 0;
}
// Display the new slide
showSlide(currentSlide);
}
// Initialize first slide
showSlide(currentSlide);
// Event listeners for navigation arrows
document.querySelector('.left-arrow').addEventListener('click', () => moveSlide(-1));
document.querySelector('.right-arrow').addEventListener('click', () => moveSlide(1));