-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (41 loc) · 1.57 KB
/
Copy pathscript.js
File metadata and controls
49 lines (41 loc) · 1.57 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
// SVG Turbulence animation
const filter = document.querySelector("#turbulence feTurbulence");
let frame = 0;
const rad = Math.PI / 180;
function animateTurbulence() {
frame += 0.5;
const bfx = 0.01 + 0.003 * Math.cos(frame * rad);
const bfy = 0.01 + 0.003 * Math.sin(frame * rad);
filter.setAttribute('baseFrequency', `${bfx} ${bfy}`);
requestAnimationFrame(animateTurbulence);
}
animateTurbulence();
// Image Slider interaction
const container = document.querySelector('.container');
const images = container.querySelectorAll('img');
// Function to set active image and center it
function setActiveImage(img) {
images.forEach(i => i.classList.remove('active'));
img.classList.add('active');
// Center the active image in the container
const containerRect = container.getBoundingClientRect();
const imgRect = img.getBoundingClientRect();
const scrollLeft = container.scrollLeft;
const offset = (imgRect.left + imgRect.width / 2) - (containerRect.left + containerRect.width / 2);
container.scrollTo({ left: scrollLeft + offset, behavior: 'smooth' });
}
// Click / tap to activate
images.forEach(img => {
img.addEventListener('click', () => setActiveImage(img));
});
// Touch swipe support
let startX = 0;
let scrollStart = 0;
container.addEventListener('touchstart', (e) => {
startX = e.touches[0].pageX;
scrollStart = container.scrollLeft;
});
container.addEventListener('touchmove', (e) => {
const x = e.touches[0].pageX;
container.scrollLeft = scrollStart + (startX - x);
});