farhan 4 meses atrás
pai
commit
73cb06592e
1 arquivos alterados com 99 adições e 123 exclusões
  1. 99
    123
      resources/js/app.js

+ 99
- 123
resources/js/app.js Ver arquivo

@@ -52,146 +52,122 @@ const countdownTimer = setInterval(() => {
52 52
     }
53 53
 }, 1000); // Update every second (1000 milliseconds)
54 54
 
55
-$(function() {
56
-    var partLeftPos = 0;
57
-    var partRightPos = 0;
58
-    var scrollTimeout;
59
-    
60
-    function debounceScroll() {
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
-        }
80
-    }
81
-
82
-    $(window).scroll(function(event) {
83
-        clearTimeout(scrollTimeout);
84
-        scrollTimeout = setTimeout(debounceScroll, 100); // Debounce scroll event
85
-    });
86
-
87
-    // Initially check visibility on page load
88
-    debounceScroll();
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
-    });
95
-
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
-                }
55
+$(document).ready(function() {
56
+    var audioElement = document.getElementById('player');
57
+    var hasPlayed = false;
58
+    var scrollCount = 0;
59
+    var maxScrolls = 8;
60
+    var scrollInterval = 200;
61
+    var scrollAmount = window.innerHeight / 6;
62
+
63
+    function playAudio() {
64
+        if (!hasPlayed) {
65
+            var playPromise = audioElement.play();
66
+            if (playPromise !== undefined) {
67
+                playPromise.then(function() {
68
+                    hasPlayed = true;
69
+                }).catch(function(error) {
70
+                    console.log('Autoplay failed: ' + error);
71
+                });
118 72
             }
119 73
         }
74
+    }
120 75
 
121
-        function smoothScroll() {
122
-            if (!hasPlayed) {
76
+    function smoothScroll() {
77
+        if (!hasPlayed) {
78
+            playAudio();
79
+            scrollCount++;
80
+            if (scrollCount >= maxScrolls) {
123 81
                 playAudio();
124
-                scrollCount++;
125
-                if (scrollCount >= maxScrolls) {
126
-                    playAudio();
82
+            } else {
83
+                var start = window.pageYOffset;
84
+                var target = start + scrollAmount;
85
+                var screenWidth = window.innerWidth;
86
+                var duration;
87
+                if (screenWidth < 600) {
88
+                    duration = 5000;
89
+                } else if (screenWidth < 1200) {
90
+                    duration = 12000;
127 91
                 } else {
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
92
+                    duration = 15000;
93
+                }
94
+                var startTime = null;
95
+
96
+                function scrollStep(timestamp) {
97
+                    if (!startTime) startTime = timestamp;
98
+                    var progress = timestamp - startTime;
99
+                    var currentPosition = start + ((target - start) * (progress / duration));
100
+                    window.scrollTo(0, currentPosition);
101
+                    if (progress < duration) {
102
+                        requestAnimationFrame(scrollStep);
137 103
                     } else {
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
-                        }
104
+                        setTimeout(smoothScroll, scrollInterval);
152 105
                     }
153
-
154
-                    requestAnimationFrame(scrollStep);
155 106
                 }
107
+
108
+                requestAnimationFrame(scrollStep);
156 109
             }
157 110
         }
111
+    }
158 112
 
159
-        function handleInteraction() {
160
-            document.body.classList.remove('no-scroll'); // Enable scrolling
161
-            setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
162
-        }
113
+    function handleInteraction() {
114
+        document.body.classList.remove('no-scroll');
115
+        setTimeout(smoothScroll, scrollInterval);
116
+    }
117
+
118
+    window.addEventListener('click', function() {
119
+        setTimeout(function() {
120
+            document.getElementById('petalOverlay').style.display = 'block';
121
+        }, 1000);
122
+    });
163 123
 
164
-        // Listen for click or touch event to start auto-scrolling
165
-        window.addEventListener('click', handleInteraction);
124
+    window.addEventListener('scroll', function() {
125
+        if (window.pageYOffset === 0) {
126
+            audioElement.pause();
127
+            document.getElementById('petalOverlay').style.display = 'none';
128
+            hasPlayed = false;
129
+            document.body.classList.add('no-scroll');
130
+        }
131
+    });
166 132
 
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');
133
+    const observerOptions = {
134
+        root: null,
135
+        rootMargin: '0px',
136
+        threshold: 0.1
137
+    };
138
+
139
+    const observer = new IntersectionObserver((entries, observer) => {
140
+        entries.forEach(entry => {
141
+            if (entry.isIntersecting) {
142
+                entry.target.classList.add('fade-in');
143
+                observer.unobserve(entry.target);
173 144
             }
174 145
         });
146
+    }, observerOptions);
175 147
 
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);
148
+    document.querySelectorAll('.fade-element').forEach(element => {
149
+        observer.observe(element);
150
+    });
191 151
 
192
-        document.querySelectorAll('.fade-element').forEach(element => {
193
-            observer.observe(element);
194
-        });
152
+    $(window).scroll(function(event) {
153
+        var distance = $(this).scrollTop() * 2;
154
+        var left = 0 - distance;
155
+        var right = 0 - distance;
156
+        
157
+        $('.left').css('left', left + "px");
158
+        $('.right').css('right', right + "px");
159
+
160
+        var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
161
+
162
+        var isLeftOffScreen = leftPartRightEdge <= 0;
163
+
164
+        if (isLeftOffScreen && left < 0) {
165
+            $('.parent').removeClass('z-30');
166
+        } else {
167
+            $('.parent').addClass('z-30');
168
+        }
195 169
     });
170
+
171
+    $(window).trigger('scroll');
196 172
 });
197 173
 

Carregando…
Cancelar
Salvar