|
@@ -56,156 +56,142 @@ $(function() {
|
56
|
56
|
var partLeftPos = 0;
|
57
|
57
|
var partRightPos = 0;
|
58
|
58
|
var scrollTimeout;
|
59
|
|
-
|
|
59
|
+
|
60
|
60
|
function debounceScroll() {
|
61
|
|
- clearTimeout(scrollTimeout);
|
62
|
|
- scrollTimeout = setTimeout(function() {
|
63
|
|
- var distance = $(window).scrollTop() * 2;
|
64
|
|
- var left = partLeftPos - distance;
|
65
|
|
- var right = partRightPos - distance;
|
66
|
|
-
|
67
|
|
- $('.left').css('left', left + "px");
|
68
|
|
- $('.right').css('right', right + "px");
|
69
|
|
-
|
70
|
|
- // Calculate boundaries
|
71
|
|
- var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
|
72
|
|
-
|
73
|
|
- // Check if both parts are completely off-screen
|
74
|
|
- var isLeftOffScreen = leftPartRightEdge <= 0;
|
75
|
|
-
|
76
|
|
- // Toggle visibility and z-index
|
77
|
|
- if (isLeftOffScreen && left < 0) {
|
78
|
|
- $('.parent').removeClass(['z-30']);
|
79
|
|
- } else {
|
80
|
|
- $('.parent').addClass(['z-30']);
|
81
|
|
- }
|
82
|
|
- }, 100); // Adjust debounce delay as needed (in milliseconds)
|
|
61
|
+ var distance = $(window).scrollTop() * 2;
|
|
62
|
+ var left = partLeftPos - distance;
|
|
63
|
+ var right = partRightPos - distance;
|
|
64
|
+
|
|
65
|
+ $('.left').css('left', left + "px");
|
|
66
|
+ $('.right').css('right', right + "px");
|
|
67
|
+
|
|
68
|
+ // Calculate boundaries
|
|
69
|
+ var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
|
|
70
|
+
|
|
71
|
+ // Check if both parts are completely off-screen
|
|
72
|
+ var isLeftOffScreen = leftPartRightEdge <= 0;
|
|
73
|
+
|
|
74
|
+ // Toggle visibility and z-index
|
|
75
|
+ if (isLeftOffScreen && left < 0) {
|
|
76
|
+ $('.parent').removeClass('z-30');
|
|
77
|
+ } else {
|
|
78
|
+ $('.parent').addClass('z-30');
|
|
79
|
+ }
|
83
|
80
|
}
|
84
|
81
|
|
85
|
82
|
$(window).scroll(function(event) {
|
86
|
|
- debounceScroll();
|
|
83
|
+ clearTimeout(scrollTimeout);
|
|
84
|
+ scrollTimeout = setTimeout(debounceScroll, 100); // Debounce scroll event
|
87
|
85
|
});
|
88
|
86
|
|
89
|
87
|
// Initially check visibility on page load
|
90
|
|
- $(window).trigger('scroll');
|
91
|
|
-});
|
|
88
|
+ debounceScroll();
|
92
|
89
|
|
|
90
|
+ document.addEventListener('click', function () {
|
|
91
|
+ setTimeout(function () {
|
|
92
|
+ document.getElementById('petalOverlay').style.display = 'block';
|
|
93
|
+ }, 1000); // Delay of 1 second (1000 milliseconds)
|
|
94
|
+ });
|
93
|
95
|
|
94
|
|
-document.addEventListener('click', function () {
|
95
|
|
- setTimeout(function () {
|
96
|
|
- document.getElementById('petalOverlay').style.display = 'block';
|
97
|
|
- }, 1000); // Delay of 1 second (1000 milliseconds)
|
98
|
|
-});
|
99
|
|
-
|
100
|
|
-document.addEventListener('DOMContentLoaded', function() {
|
101
|
|
- var audioElement = document.getElementById('player');
|
102
|
|
- var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
|
103
|
|
- var scrollCount = 0;
|
104
|
|
- var maxScrolls = 8;
|
105
|
|
- var scrollInterval = 200; // Time in milliseconds between each scroll
|
106
|
|
- var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
|
107
|
|
-
|
108
|
|
- function playAudio() {
|
109
|
|
- if (!hasPlayed) {
|
110
|
|
- console.log('play')
|
111
|
|
- var playPromise = audioElement.play();
|
112
|
|
-
|
113
|
|
- if (playPromise !== undefined) {
|
114
|
|
- playPromise.then(function() {
|
115
|
|
- // Automatic playback started!
|
116
|
|
- hasPlayed = true; // Prevent further attempts to play
|
117
|
|
- }).catch(function(error) {
|
118
|
|
- // Automatic playback failed.
|
119
|
|
- console.log('Autoplay failed: ' + error);
|
120
|
|
- });
|
|
96
|
+ document.addEventListener('DOMContentLoaded', function() {
|
|
97
|
+ var audioElement = document.getElementById('player');
|
|
98
|
+ var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
|
|
99
|
+ var scrollCount = 0;
|
|
100
|
+ var maxScrolls = 8;
|
|
101
|
+ var scrollInterval = 200; // Time in milliseconds between each scroll
|
|
102
|
+ var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
|
|
103
|
+
|
|
104
|
+ function playAudio() {
|
|
105
|
+ if (!hasPlayed) {
|
|
106
|
+ console.log('play');
|
|
107
|
+ var playPromise = audioElement.play();
|
|
108
|
+
|
|
109
|
+ if (playPromise !== undefined) {
|
|
110
|
+ playPromise.then(function() {
|
|
111
|
+ // Automatic playback started!
|
|
112
|
+ hasPlayed = true; // Prevent further attempts to play
|
|
113
|
+ }).catch(function(error) {
|
|
114
|
+ // Automatic playback failed.
|
|
115
|
+ console.log('Autoplay failed: ' + error);
|
|
116
|
+ });
|
|
117
|
+ }
|
121
|
118
|
}
|
122
|
119
|
}
|
123
|
|
- }
|
124
|
120
|
|
125
|
|
- function smoothScroll() {
|
126
|
|
- if (!hasPlayed) {
|
127
|
|
- playAudio();
|
128
|
|
- scrollCount++;
|
129
|
|
- if (scrollCount >= maxScrolls) {
|
|
121
|
+ function smoothScroll() {
|
|
122
|
+ if (!hasPlayed) {
|
130
|
123
|
playAudio();
|
131
|
|
- } else {
|
132
|
|
- var start = window.pageYOffset;
|
133
|
|
- var target = start + scrollAmount;
|
134
|
|
- // Set duration based on screen size
|
135
|
|
- var screenWidth = window.innerWidth;
|
136
|
|
- var duration;
|
137
|
|
- if (screenWidth < 600) {
|
138
|
|
- duration = 5000; // Smaller screen
|
139
|
|
- } else if (screenWidth < 1200) {
|
140
|
|
- duration = 12000; // Medium screen
|
|
124
|
+ scrollCount++;
|
|
125
|
+ if (scrollCount >= maxScrolls) {
|
|
126
|
+ playAudio();
|
141
|
127
|
} else {
|
142
|
|
- duration = 15000; // Larger screen
|
143
|
|
- }
|
144
|
|
- var startTime = null;
|
145
|
|
-
|
146
|
|
- function scrollStep(timestamp) {
|
147
|
|
- if (!startTime) startTime = timestamp;
|
148
|
|
- var progress = timestamp - startTime;
|
149
|
|
- var currentPosition = start + ((target - start) * (progress / duration));
|
150
|
|
- window.scrollTo(0, currentPosition);
|
151
|
|
- if (progress < duration) {
|
152
|
|
- requestAnimationFrame(scrollStep);
|
|
128
|
+ var start = window.pageYOffset;
|
|
129
|
+ var target = start + scrollAmount;
|
|
130
|
+ // Set duration based on screen size
|
|
131
|
+ var screenWidth = window.innerWidth;
|
|
132
|
+ var duration;
|
|
133
|
+ if (screenWidth < 600) {
|
|
134
|
+ duration = 5000; // Smaller screen
|
|
135
|
+ } else if (screenWidth < 1200) {
|
|
136
|
+ duration = 12000; // Medium screen
|
153
|
137
|
} else {
|
154
|
|
- setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
|
|
138
|
+ duration = 15000; // Larger screen
|
|
139
|
+ }
|
|
140
|
+ var startTime = null;
|
|
141
|
+
|
|
142
|
+ function scrollStep(timestamp) {
|
|
143
|
+ if (!startTime) startTime = timestamp;
|
|
144
|
+ var progress = timestamp - startTime;
|
|
145
|
+ var currentPosition = start + ((target - start) * (progress / duration));
|
|
146
|
+ window.scrollTo(0, currentPosition);
|
|
147
|
+ if (progress < duration) {
|
|
148
|
+ requestAnimationFrame(scrollStep);
|
|
149
|
+ } else {
|
|
150
|
+ setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
|
|
151
|
+ }
|
155
|
152
|
}
|
156
|
|
- }
|
157
|
153
|
|
158
|
|
- requestAnimationFrame(scrollStep);
|
|
154
|
+ requestAnimationFrame(scrollStep);
|
|
155
|
+ }
|
159
|
156
|
}
|
160
|
157
|
}
|
161
|
|
- }
|
162
|
158
|
|
163
|
|
- function playOnly() {
|
164
|
|
- if (!hasPlayed) {
|
165
|
|
- playAudio();
|
166
|
|
- scrollCount++;
|
167
|
|
- if (scrollCount >= maxScrolls) {
|
168
|
|
- playAudio();
|
169
|
|
- } else {
|
170
|
|
- setTimeout(playOnly, scrollInterval);
|
171
|
|
- }
|
|
159
|
+ function handleInteraction() {
|
|
160
|
+ document.body.classList.remove('no-scroll'); // Enable scrolling
|
|
161
|
+ setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
|
172
|
162
|
}
|
173
|
|
- }
|
174
|
|
-
|
175
|
|
- function handleInteraction() {
|
176
|
|
- document.body.classList.remove('no-scroll'); // Enable scrolling
|
177
|
|
- setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
|
178
|
|
- }
|
179
|
|
-
|
180
|
|
- // Listen for click or touch event to start auto-scrolling
|
181
|
|
- window.addEventListener('click', handleInteraction);
|
182
|
163
|
|
183
|
|
- window.addEventListener('scroll', function() {
|
184
|
|
- if (window.pageYOffset === 0) {
|
185
|
|
- audioElement.pause();
|
186
|
|
- document.getElementById('petalOverlay').style.display = 'none';
|
187
|
|
- hasPlayed = false; // Reset to allow replay
|
188
|
|
- document.body.classList.add('no-scroll');
|
189
|
|
- }
|
190
|
|
- });
|
|
164
|
+ // Listen for click or touch event to start auto-scrolling
|
|
165
|
+ window.addEventListener('click', handleInteraction);
|
191
|
166
|
|
192
|
|
- // Intersection Observer for fading in elements
|
193
|
|
- const observerOptions = {
|
194
|
|
- root: null,
|
195
|
|
- rootMargin: '0px',
|
196
|
|
- threshold: 0.1
|
197
|
|
- };
|
198
|
|
-
|
199
|
|
- const observer = new IntersectionObserver((entries, observer) => {
|
200
|
|
- entries.forEach(entry => {
|
201
|
|
- if (entry.isIntersecting) {
|
202
|
|
- entry.target.classList.add('fade-in');
|
203
|
|
- observer.unobserve(entry.target);
|
|
167
|
+ window.addEventListener('scroll', function() {
|
|
168
|
+ if (window.pageYOffset === 0) {
|
|
169
|
+ audioElement.pause();
|
|
170
|
+ document.getElementById('petalOverlay').style.display = 'none';
|
|
171
|
+ hasPlayed = false; // Reset to allow replay
|
|
172
|
+ document.body.classList.add('no-scroll');
|
204
|
173
|
}
|
205
|
174
|
});
|
206
|
|
- }, observerOptions);
|
207
|
175
|
|
208
|
|
- document.querySelectorAll('.fade-element').forEach(element => {
|
209
|
|
- observer.observe(element);
|
|
176
|
+ // Intersection Observer for fading in elements
|
|
177
|
+ const observerOptions = {
|
|
178
|
+ root: null,
|
|
179
|
+ rootMargin: '0px',
|
|
180
|
+ threshold: 0.1
|
|
181
|
+ };
|
|
182
|
+
|
|
183
|
+ const observer = new IntersectionObserver((entries, observer) => {
|
|
184
|
+ entries.forEach(entry => {
|
|
185
|
+ if (entry.isIntersecting) {
|
|
186
|
+ entry.target.classList.add('fade-in');
|
|
187
|
+ observer.unobserve(entry.target);
|
|
188
|
+ }
|
|
189
|
+ });
|
|
190
|
+ }, observerOptions);
|
|
191
|
+
|
|
192
|
+ document.querySelectorAll('.fade-element').forEach(element => {
|
|
193
|
+ observer.observe(element);
|
|
194
|
+ });
|
210
|
195
|
});
|
211
|
196
|
});
|
|
197
|
+
|