-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
99 lines (85 loc) · 2.93 KB
/
main.js
File metadata and controls
99 lines (85 loc) · 2.93 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Smooth Scroll Implementation
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Intersection Observer for Animations
const animateOnScroll = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fadeUp');
}
});
}, {
threshold: 0.1
});
document.querySelectorAll('.card, .feature-card, .stat-card').forEach((element) => {
animateOnScroll.observe(element);
});
// Navbar Scroll Effect
let lastScroll = 0;
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll <= 0) {
navbar.classList.remove('scroll-up');
return;
}
if (currentScroll > lastScroll && !navbar.classList.contains('scroll-down')) {
navbar.classList.remove('scroll-up');
navbar.classList.add('scroll-down');
} else if (currentScroll < lastScroll && navbar.classList.contains('scroll-down')) {
navbar.classList.remove('scroll-down');
navbar.classList.add('scroll-up');
}
lastScroll = currentScroll;
});
// Copy Address Function with Modern Toast
function copyAddress() {
const address = '0x45f87973fd2837309422d044a58159a2bf7b0dfb';
navigator.clipboard.writeText(address).then(() => {
showToast('Address copied to clipboard!', 'success');
}).catch(() => {
showToast('Failed to copy address', 'error');
});
}
function showToast(message, type = 'success') {
const toast = document.createElement('div');
toast.className = `toast toast-${type} animate-fadeUp`;
toast.innerHTML = `
<i class="fas fa-${type === 'success' ? 'check-circle' : 'exclamation-circle'}"></i>
<span>${message}</span>
`;
document.getElementById('toast-container').appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
setTimeout(() => toast.remove(), 300);
}, 3000);
}
// Dynamic Stats Counter
function animateValue(obj, start, end, duration) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
obj.innerHTML = Math.floor(progress * (end - start) + start).toLocaleString();
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
// Initialize Stats Animation
document.querySelectorAll('.stat-value').forEach(stat => {
const finalValue = parseInt(stat.getAttribute('data-value'));
animateValue(stat, 0, finalValue, 2000);
});
// Mobile Menu Toggle
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
menuToggle?.addEventListener('click', () => {
navLinks.classList.toggle('active');