Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (59 loc) · 2.49 KB
/
Copy pathscript.js
File metadata and controls
66 lines (59 loc) · 2.49 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
document.addEventListener('DOMContentLoaded', function () {
// ===== 1. LOGIKA KUSTOM KURSOR & SOROTAN LATAR =====
const cursor = document.querySelector('.custom-cursor');
const hoverableElements = document.querySelectorAll('a, .card');
function moveCursor(e) {
cursor.style.left = `${e.clientX}px`;
cursor.style.top = `${e.clientY}px`;
document.documentElement.style.setProperty('--mouse-x', `${e.clientX}px`);
document.documentElement.style.setProperty('--mouse-y', `${e.clientY}px`);
}
hoverableElements.forEach(el => {
el.addEventListener('mouseover', () => cursor.classList.add('hover'));
el.addEventListener('mouseout', () => cursor.classList.remove('hover'));
});
window.addEventListener('mousedown', () => cursor.classList.add('click'));
window.addEventListener('mouseup', () => cursor.classList.remove('click'));
window.addEventListener('mousemove', moveCursor);
// ===== 2. LOGIKA EFEK GELOMBANG SAAT KLIK (RIPPLE) =====
document.addEventListener('click', function (e) {
const ripple = document.createElement('span');
ripple.classList.add('ripple');
document.body.appendChild(ripple);
ripple.style.left = `${e.clientX - ripple.clientWidth / 2}px`;
ripple.style.top = `${e.clientY - ripple.clientHeight / 2}px`;
setTimeout(() => {
ripple.remove();
}, 600);
});
// ===== 3. LOGIKA ANIMASI SCROLL =====
const cards = document.querySelectorAll('.card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1
});
cards.forEach(card => {
observer.observe(card);
});
// ===== 4. LOGIKA SMOOTH SCROLL =====
const navLinks = document.querySelectorAll('.section-nav a');
navLinks.forEach(link => {
link.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
targetSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
});