Browse Source

remove refactor

master
farhan 5 months ago
parent
commit
e897a52939
1 changed files with 88 additions and 197 deletions
  1. 88
    197
      resources/js/app.js

+ 88
- 197
resources/js/app.js View File

@@ -52,17 +52,66 @@ const countdownTimer = setInterval(() => {
52 52
     }
53 53
 }, 1000); // Update every second (1000 milliseconds)
54 54
 
55
-$(document).ready(function() {
55
+$(function() {
56 56
     var partLeftPos = 0;
57 57
     var partRightPos = 0;
58
+    
59
+    $(window).scroll(function(event) {
60
+        var distance = $(this).scrollTop() * 2;
61
+        var left = partLeftPos - distance;
62
+        var right = partRightPos - distance;
63
+        
64
+        $('.left').css('left', left + "px");
65
+        $('.right').css('right', right + "px");
66
+
67
+        // Calculate boundaries
68
+        var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
69
+
70
+        // Check if both parts are completely off-screen
71
+        var isLeftOffScreen = leftPartRightEdge <= 0;
72
+
73
+        // Toggle visibility and z-index
74
+        if (isLeftOffScreen && left < 0) {
75
+            $('.parent').removeClass(['z-30']);
76
+        } else {
77
+            $('.parent').addClass(['z-30']);
78
+        }
79
+    });
80
+    // Initially check visibility on page load
81
+    $(window).trigger('scroll');
82
+});
83
+
84
+document.addEventListener('click', function () {
85
+    setTimeout(function () {
86
+        document.getElementById('petalOverlay').style.display = 'block';
87
+    }, 1000); // Delay of 1 second (1000 milliseconds)
88
+});
89
+
90
+document.addEventListener('DOMContentLoaded', function() {
58 91
     var audioElement = document.getElementById('player');
59
-    var hasPlayed = false;
92
+    var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
60 93
     var scrollCount = 0;
61 94
     var maxScrolls = 8;
62
-    var scrollInterval = 200;
63
-    var scrollAmount = window.innerHeight / 6;
95
+    var scrollInterval = 200; // Time in milliseconds between each scroll
96
+    var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
97
+
98
+    function playAudio() {
99
+        if (!hasPlayed) {
100
+            console.log('play')
101
+            var playPromise = audioElement.play();
102
+
103
+            if (playPromise !== undefined) {
104
+                playPromise.then(function() {
105
+                    // Automatic playback started!
106
+                    hasPlayed = true; // Prevent further attempts to play
107
+                }).catch(function(error) {
108
+                    // Automatic playback failed.
109
+                    console.log('Autoplay failed: ' + error);
110
+                });
111
+            }
112
+        }
113
+    }
64 114
 
65
-    // Function to handle smooth scrolling
66 115
     function smoothScroll() {
67 116
         if (!hasPlayed) {
68 117
             playAudio();
@@ -72,9 +121,9 @@ $(document).ready(function() {
72 121
             } else {
73 122
                 var start = window.pageYOffset;
74 123
                 var target = start + scrollAmount;
124
+                 // Set duration based on screen size
75 125
                 var screenWidth = window.innerWidth;
76 126
                 var duration;
77
-
78 127
                 if (screenWidth < 600) {
79 128
                     duration = 5000; // Smaller screen
80 129
                 } else if (screenWidth < 1200) {
@@ -82,7 +131,6 @@ $(document).ready(function() {
82 131
                 } else {
83 132
                     duration = 15000; // Larger screen
84 133
                 }
85
-
86 134
                 var startTime = null;
87 135
 
88 136
                 function scrollStep(timestamp) {
@@ -102,209 +150,52 @@ $(document).ready(function() {
102 150
         }
103 151
     }
104 152
 
105
-    // Function to play audio (if not already played)
106
-    function playAudio() {
153
+    function playOnly() {
107 154
         if (!hasPlayed) {
108
-            var playPromise = audioElement.play();
109
-
110
-            if (playPromise !== undefined) {
111
-                playPromise.then(function() {
112
-                    hasPlayed = true;
113
-                }).catch(function(error) {
114
-                    console.log('Autoplay failed: ' + error);
115
-                });
155
+            playAudio();
156
+            scrollCount++;
157
+            if (scrollCount >= maxScrolls) {
158
+                playAudio();
159
+            } else {
160
+                setTimeout(playOnly, scrollInterval);
116 161
             }
117 162
         }
118 163
     }
119 164
 
120
-    // jQuery scroll event handling
121
-    $(window).scroll(function() {
122
-        var distance = $(this).scrollTop() * 2;
123
-        var left = partLeftPos - distance;
124
-        var right = partRightPos - distance;
125
-
126
-        $('.left').css('left', left + "px");
127
-        $('.right').css('right', right + "px");
128
-
129
-        var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
130
-        var isLeftOffScreen = leftPartRightEdge <= 0;
131
-
132
-        if (isLeftOffScreen && left < 0) {
133
-            $('.parent').removeClass('z-30');
134
-        } else {
135
-            $('.parent').addClass('z-30');
136
-        }
137
-    });
138
-
139
-    // Initially check visibility on page load
140
-    $(window).trigger('scroll');
165
+    function handleInteraction() {
166
+        document.body.classList.remove('no-scroll'); // Enable scrolling
167
+        setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
168
+    }
141 169
 
142
-    // Event listener for click to show overlay after a delay
143
-    document.addEventListener('click', function() {
144
-        setTimeout(function() {
145
-            document.getElementById('petalOverlay').style.display = 'block';
146
-        }, 1000); // Delay of 1 second (1000 milliseconds)
147
-    });
170
+    // Listen for click or touch event to start auto-scrolling
171
+    window.addEventListener('click', handleInteraction);
148 172
 
149
-    // Event listener for scroll to reset audio and overlay if scrolled to top
150 173
     window.addEventListener('scroll', function() {
151 174
         if (window.pageYOffset === 0) {
152 175
             audioElement.pause();
153 176
             document.getElementById('petalOverlay').style.display = 'none';
154
-            hasPlayed = false;
177
+            hasPlayed = false; // Reset to allow replay
155 178
             document.body.classList.add('no-scroll');
156 179
         }
157 180
     });
158
-});
159
-
160 181
 
161
-// $(function() {
162
-//     var partLeftPos = 0;
163
-//     var partRightPos = 0;
164
-    
165
-//     $(window).scroll(function(event) {
166
-//         var distance = $(this).scrollTop() * 2;
167
-//         var left = partLeftPos - distance;
168
-//         var right = partRightPos - distance;
169
-        
170
-//         $('.left').css('left', left + "px");
171
-//         $('.right').css('right', right + "px");
172
-
173
-//         // Calculate boundaries
174
-//         var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
175
-
176
-//         // Check if both parts are completely off-screen
177
-//         var isLeftOffScreen = leftPartRightEdge <= 0;
178
-
179
-//         // Toggle visibility and z-index
180
-//         if (isLeftOffScreen && left < 0) {
181
-//             $('.parent').removeClass(['z-30']);
182
-//         } else {
183
-//             $('.parent').addClass(['z-30']);
184
-//         }
185
-//     });
186
-
187
-//     // Initially check visibility on page load
188
-//     $(window).trigger('scroll');
189
-
190
-    
191
-// });
192
-
193
-// document.addEventListener('click', function () {
194
-//     setTimeout(function () {
195
-//         document.getElementById('petalOverlay').style.display = 'block';
196
-//     }, 1000); // Delay of 1 second (1000 milliseconds)
197
-// });
198
-
199
-// document.addEventListener('DOMContentLoaded', function() {
200
-//     var audioElement = document.getElementById('player');
201
-//     var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
202
-//     var scrollCount = 0;
203
-//     var maxScrolls = 8;
204
-//     var scrollInterval = 200; // Time in milliseconds between each scroll
205
-//     var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
206
-
207
-//     function playAudio() {
208
-//         if (!hasPlayed) {
209
-//             console.log('play')
210
-//             var playPromise = audioElement.play();
211
-
212
-//             if (playPromise !== undefined) {
213
-//                 playPromise.then(function() {
214
-//                     // Automatic playback started!
215
-//                     hasPlayed = true; // Prevent further attempts to play
216
-//                 }).catch(function(error) {
217
-//                     // Automatic playback failed.
218
-//                     console.log('Autoplay failed: ' + error);
219
-//                 });
220
-//             }
221
-//         }
222
-//     }
223
-
224
-//     function smoothScroll() {
225
-//         if (!hasPlayed) {
226
-//             playAudio();
227
-//             scrollCount++;
228
-//             if (scrollCount >= maxScrolls) {
229
-//                 playAudio();
230
-//             } else {
231
-//                 var start = window.pageYOffset;
232
-//                 var target = start + scrollAmount;
233
-//                  // Set duration based on screen size
234
-//                 var screenWidth = window.innerWidth;
235
-//                 var duration;
236
-//                 if (screenWidth < 600) {
237
-//                     duration = 5000; // Smaller screen
238
-//                 } else if (screenWidth < 1200) {
239
-//                     duration = 12000; // Medium screen
240
-//                 } else {
241
-//                     duration = 15000; // Larger screen
242
-//                 }
243
-//                 var startTime = null;
244
-
245
-//                 function scrollStep(timestamp) {
246
-//                     if (!startTime) startTime = timestamp;
247
-//                     var progress = timestamp - startTime;
248
-//                     var currentPosition = start + ((target - start) * (progress / duration));
249
-//                     window.scrollTo(0, currentPosition);
250
-//                     if (progress < duration) {
251
-//                         requestAnimationFrame(scrollStep);
252
-//                     } else {
253
-//                         setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
254
-//                     }
255
-//                 }
256
-
257
-//                 requestAnimationFrame(scrollStep);
258
-//             }
259
-//         }
260
-//     }
261
-
262
-//     function playOnly() {
263
-//         if (!hasPlayed) {
264
-//             playAudio();
265
-//             scrollCount++;
266
-//             if (scrollCount >= maxScrolls) {
267
-//                 playAudio();
268
-//             } else {
269
-//                 setTimeout(playOnly, scrollInterval);
270
-//             }
271
-//         }
272
-//     }
273
-
274
-//     function handleInteraction() {
275
-//         document.body.classList.remove('no-scroll'); // Enable scrolling
276
-//         setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
277
-//     }
278
-
279
-//     // Listen for click or touch event to start auto-scrolling
280
-//     window.addEventListener('click', handleInteraction);
281
-
282
-//     window.addEventListener('scroll', function() {
283
-//         if (window.pageYOffset === 0) {
284
-//             audioElement.pause();
285
-//             document.getElementById('petalOverlay').style.display = 'none';
286
-//             hasPlayed = false; // Reset to allow replay
287
-//             document.body.classList.add('no-scroll');
288
-//         }
289
-//     });
290
-
291
-//      // Intersection Observer for fading in elements
292
-//     const observerOptions = {
293
-//         root: null,
294
-//         rootMargin: '0px',
295
-//         threshold: 0.1
296
-//     };
297
-
298
-//     const observer = new IntersectionObserver((entries, observer) => {
299
-//         entries.forEach(entry => {
300
-//             if (entry.isIntersecting) {
301
-//                 entry.target.classList.add('fade-in');
302
-//                 observer.unobserve(entry.target);
303
-//             }
304
-//         });
305
-//     }, observerOptions);
182
+     // Intersection Observer for fading in elements
183
+    const observerOptions = {
184
+        root: null,
185
+        rootMargin: '0px',
186
+        threshold: 0.1
187
+    };
188
+
189
+    const observer = new IntersectionObserver((entries, observer) => {
190
+        entries.forEach(entry => {
191
+            if (entry.isIntersecting) {
192
+                entry.target.classList.add('fade-in');
193
+                observer.unobserve(entry.target);
194
+            }
195
+        });
196
+    }, observerOptions);
306 197
 
307
-//     document.querySelectorAll('.fade-element').forEach(element => {
308
-//         observer.observe(element);
309
-//     });
310
-// });
198
+    document.querySelectorAll('.fade-element').forEach(element => {
199
+        observer.observe(element);
200
+    });
201
+});

Loading…
Cancel
Save