-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
371 lines (300 loc) · 9.86 KB
/
index.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
// preloader
// JavaScript to handle the loader display
setTimeout(function() {
// Hide the loader after 10 seconds
var loader = $('.reload-container');
if (loader) {
loader.hide();
$('body').css('filter', 'none'); // Remove the blur effect
}
}, 2000); // Display the loader for 10 seconds
// checkbox js
// checkbox js
var checkbox = document.getElementById('check');
var lstitem = document.querySelectorAll('.item_sec')[0];
var listItems = document.querySelectorAll('.item_sec li');
function toggleListItems() {
if (window.innerWidth <= 777) {
lstitem.style.display = 'none';
checkbox.addEventListener('change', function() {
lstitem.style.display = 'block';
if (checkbox.checked) {
listItems.forEach(function(item) {
item.style.display = 'block';
});
// Add click event listener to each list item
listItems.forEach(function(item) {
item.addEventListener('click', itemClickHandler);
});
} else {
listItems.forEach(function(item) {
item.style.display = 'none';
});
// Remove the click event listener when the checkbox is unchecked
listItems.forEach(function(item) {
item.removeEventListener('click', itemClickHandler);
});
}
});
} else {
// If the screen width is above 777px, ensure that list items are always displayed
listItems.forEach(function(item) {
item.style.display = 'block';
lstitem.style.display = 'flex';
});
// Remove the click event listener when the window width is above 777px
listItems.forEach(function(item) {
item.removeEventListener('click', itemClickHandler);
});
}
}
// Click event handler function
function itemClickHandler() {
checkbox.checked = false;
lstitem.style.display = 'none';
}
// Initially check the window width and apply the appropriate behavior
toggleListItems();
// Add an event listener to the window's resize event
window.addEventListener('resize', toggleListItems);
function Ticker( elem ) {
elem.lettering();
this.done = false;
this.cycleCount = 5;
this.cycleCurrent = 0;
this.chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+{}|[]\\;\':"<>?,./`~'.split('');
this.charsCount = this.chars.length;
this.letters = elem.find( 'span' );
this.letterCount = this.letters.length;
this.letterCurrent = 0;
this.letters.each( function() {
var $this = $( this );
$this.attr( 'data-orig', $this.text() );
$this.text( '-' );
});
}
Ticker.prototype.getChar = function() {
return this.chars[ Math.floor( Math.random() * this.charsCount ) ];
};
Ticker.prototype.reset = function() {
this.done = false;
this.cycleCurrent = 0;
this.letterCurrent = 0;
this.letters.each( function() {
var $this = $( this );
$this.text( $this.attr( 'data-orig' ) );
$this.removeClass( 'done' );
});
this.loop();
};
Ticker.prototype.loop = function() {
var self = this;
this.letters.each( function( index, elem ) {
var $elem = $( elem );
if( index >= self.letterCurrent ) {
if( $elem.text() !== ' ' ) {
$elem.text( self.getChar() );
$elem.css( 'opacity', Math.random() );
}
}
});
if( this.cycleCurrent < this.cycleCount ) {
this.cycleCurrent++;
} else if( this.letterCurrent < this.letterCount ) {
var currLetter = this.letters.eq( this.letterCurrent );
this.cycleCurrent = 0;
currLetter.text( currLetter.attr( 'data-orig' ) ).css( 'opacity', 1 ).addClass( 'done' );
this.letterCurrent++;
} else {
this.done = true;
}
if( !this.done ) {
requestAnimationFrame( function() {
self.loop();
});
} else {
setTimeout( function() {
self.reset();
}, 750 );
}
};
$words = $( '.word' );
$words.each( function() {
var $this = $( this ),
ticker = new Ticker( $this ).reset();
$this.data( 'ticker', ticker );
});
// preloader
// cursor script
const cursorCanvas = document.getElementById("cursorCanvas");
const cursorCtx = cursorCanvas.getContext("2d");
// Resize cursor canvas to fit window
cursorCanvas.width = window.innerWidth;
cursorCanvas.height = window.innerHeight;
class Sparkle {
constructor(x, y) {
this.x = x;
this.y = y;
this.size = Math.random() * 6 + 1;
// Set speed based on the opposite direction of mouse movement
const speedFactor = length * 0.05; // Adjust the 0.05 multiplier as needed
this.speedX = -directionX * speedFactor * (Math.random() * 2 + 1); // Adjust the multiplier as needed for desired speed
this.speedY = -directionY * speedFactor * (Math.random() * 2 + 1);
this.alpha = 1;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
this.alpha -= 0.03; // Decrease alpha over time, this will make the sparkle fade away
}
draw() {
cursorCtx.beginPath();
cursorCtx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
const gradient = cursorCtx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.size);
gradient.addColorStop(0, 'rgba(232, 28, 255, ' + this.alpha + ')');
gradient.addColorStop(1, 'rgba(64, 201, 255, ' + this.alpha + ')');
cursorCtx.fillStyle = gradient;
cursorCtx.fill();
cursorCtx.closePath();
}
}
let sparkles = [];
// Update and draw sparkles
function handleSparkles() {
cursorCtx.clearRect(0, 0, cursorCanvas.width, cursorCanvas.height);
if (isMouseMoving) {
// Only add a sparkle if the mouse is moving
sparkles.push(new Sparkle(mouseX, mouseY));
}
// Loop over sparkles to update and draw each one
for (let i = sparkles.length - 1; i >= 0; i--) {
sparkles[i].update();
sparkles[i].draw();
// Remove the sparkle if its alpha has become less than or equal to 0
if (sparkles[i].alpha <= 0) {
sparkles.splice(i, 1);
}
}
requestAnimationFrame(handleSparkles);
}
let mouseX = 0;
let mouseY = 0;
let prevMouseX = 0;
let prevMouseY = 0;
let isMouseMoving = false;
let mouseMoveTimeout;
let directionX = 0;
let directionY = 0;
let length = 1;
// Update mouse position
document.addEventListener("mousemove", (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
isMouseMoving = true;
// Calculate direction of mouse movement
const dx = mouseX - prevMouseX;
const dy = mouseY - prevMouseY;
// Normalize the direction (make its length equal to 1)
length = Math.sqrt(dx * dx + dy * dy);
directionX = length ? dx / length : 0;
directionY = length ? dy / length : 0;
prevMouseX = mouseX;
prevMouseY = mouseY;
// Reset the flag after a short delay
clearTimeout(mouseMoveTimeout);
mouseMoveTimeout = setTimeout(() => {
isMouseMoving = false;
}, 50);
});
handleSparkles();
// Optional: Resize canvas and redraw stars when the window is resized
window.addEventListener("resize", function () {
cursorCanvas.width = window.innerWidth;
cursorCanvas.height = window.innerHeight;
});
// cursor script end
// typing js start
const typer = document.getElementById('main-typer');
const words = typer.getAttribute('data-words').split(',');
const delay = parseInt(typer.getAttribute('data-delay'));
const deleteDelay = parseInt(typer.getAttribute('data-deleteDelay'));
let wordIndex = 0;
let isDeleting = false;
let text = '';
function type() {
const currentWord = words[wordIndex];
if (isDeleting) {
text = currentWord.substring(0, text.length - 1);
} else {
text = currentWord.substring(0, text.length + 1);
}
typer.textContent = text;
if (!isDeleting && text === currentWord) {
isDeleting = true;
setTimeout(type, deleteDelay);
} else if (isDeleting && text === '') {
isDeleting = false;
wordIndex = (wordIndex + 1) % words.length;
setTimeout(type, delay);
} else {
setTimeout(type, isDeleting ? 50 : 100);
}
}
type(); // Start the animation
// typing js end
// skills section
// JavaScript
'use strict';
function animateProgressBars(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const progressBars = entry.target.querySelectorAll('.progress');
let increment = 1; // Change the increment value for the speed of the animation
let intervalDuration = 20; // Change the duration for the interval
progressBars.forEach(progressBar => {
const maxProgress = progressBar.dataset.progress;
let currentProgress = 0;
const interval = setInterval(() => {
currentProgress += increment;
if (currentProgress > maxProgress) {
clearInterval(interval);
} else {
progressBar.style.background = `conic-gradient(#f9004d ${currentProgress}%, #212428 0)`;
progressBar.querySelector('.progress-number').textContent = `${currentProgress}%`;
}
}, intervalDuration);
});
// Unobserve after starting the animation to prevent it from repeating
observer.unobserve(entry.target);
}
});
}
const skillSections = document.querySelectorAll('.skill_sec');
const observer = new IntersectionObserver(animateProgressBars, {
root: null,
rootMargin: '0px',
threshold: 0.5, // Adjust this value to control when the animation starts
});
skillSections.forEach(section => {
observer.observe(section);
});
// project section
$(function () {
var filterList = {
init: function () {
// MixItUp plugin
// http://mixitup.io
$('.portfolio-grid').mixItUp({
selectors: {
target: '.portfolio',
filter: '.filter'
},
load: {
filter: 'all' // show app tab on first load
}
});
}
};
// Run the show!
filterList.init();
});