-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
129 lines (107 loc) · 3.95 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
function ToggleMenu(){
const menu = document.querySelector(".menu-links");
const icon = document.querySelector(".main-icon");
menu.classList.toggle("open");
icon.classList.toggle("open");
}
document.addEventListener('DOMContentLoaded', function() {
const sliders = document.querySelectorAll('.slider');
sliders.forEach((slider, index) => {
const images = slider.querySelectorAll('img');
const navDots = slider.parentElement.querySelectorAll('.nav-dot');
const imageCount = images.length;
let currentIndex = 0;
function showNextImage() {
currentIndex = (currentIndex + 1) % imageCount;
slider.scrollLeft = slider.offsetWidth * currentIndex;
updateNavDots();
}
function updateNavDots() {
navDots.forEach((dot, i) => {
dot.classList.toggle('active', i === currentIndex);
});
}
navDots.forEach((dot, i) => {
dot.addEventListener('click', (e) => {
e.preventDefault();
currentIndex = i;
slider.scrollLeft = slider.offsetWidth * currentIndex;
updateNavDots();
});
});
// Change image every 2 seconds
setInterval(showNextImage, 2000);
});
});
const svg = document.getElementById('ocean');
// Generates a soft ocean blue shade
const randomBlueShade = () => {
const r = 0;
const g = Math.floor(Math.random() * 100) + 100; // Lighter blue-green shades
const b = Math.floor(Math.random() * 200) + 55; // Deeper blues with some variations
const a = Math.random() * 0.4 + 0.4; // Opacity between 0.4 and 0.8 for soft waves
return `rgba(${r}, ${g}, ${b}, ${a})`;
};
const createWave = (y, amplitude, frequency, phase, color) => {
const wave = document.createElementNS('http://www.w3.org/2000/svg', 'path');
wave.setAttribute('fill', color);
svg.appendChild(wave);
return { wave, y, amplitude, frequency, phase, color };
};
const waves = Array.from({ length: 80 }, () => // Reduced number of waves for smoother look
createWave(
Math.random() * window.innerHeight, // Random Y position
Math.random() * 40 + 30, // Random amplitude for smaller, gentle waves
Math.random() * 250 + 150, // Random frequency for more relaxed motion
Math.random() * Math.PI * 2, // Random phase for variation
randomBlueShade() // Use new soothing blue shades
)
);
const updateWavePath = (waveObj, time) => {
const { wave, y, amplitude, frequency, phase } = waveObj;
let path = `M 0 ${y}`;
for (let x = 0; x <= window.innerWidth; x += 10) {
const offsetY = amplitude * Math.sin((x / frequency) + phase + time);
path += ` L ${x} ${y + offsetY}`;
}
path += ` L ${window.innerWidth} ${window.innerHeight} L 0 ${window.innerHeight} Z`;
wave.setAttribute('d', path);
};
const animate = () => {
const time = Date.now() * 0.002;
waves.forEach(waveObj => {
updateWavePath(waveObj, time);
waveObj.phase += Math.random() * 0.02 - 0.01; // Slightly randomize movement
});
requestAnimationFrame(animate);
};
const init = () => {
svg.setAttribute('width', window.innerWidth);
svg.setAttribute('height', window.innerHeight);
animate();
};
window.addEventListener('resize', () => {
svg.innerHTML = ''; // Clear existing waves
waves.length = 0;
waves.push(...Array.from({ length: 80 }, () =>
createWave(
Math.random() * window.innerHeight,
Math.random() * 40 + 30,
Math.random() * 250 + 150,
Math.random() * Math.PI * 2,
randomBlueShade()
)
));
init();
});
init();
// let intervalId;
// function startSlider() {
// intervalId = setInterval(showNextImage, 2000);
// }
// function stopSlider() {
// clearInterval(intervalId);
// }
// slider.addEventListener('mouseover', stopSlider);
// slider.addEventListener('mouseout', startSlider);
// startSlider();