Browse Source

revert back cover openclose logic

master
azri 5 months ago
parent
commit
35cb63957b
2 changed files with 74 additions and 62 deletions
  1. 0
    32
      resources/css/app.css
  2. 74
    30
      resources/js/app.js

+ 0
- 32
resources/css/app.css View File

@@ -107,39 +107,7 @@ body.no-scroll {
107 107
     transition: all 0.1s ease-in-out;
108 108
 }
109 109
 
110
-@keyframes to-left{
111
-    from{
112
-        transform: translateX(0%);
113
-    }
114
-    to{
115
-        transform: translateX(-100%);
116
-    }
117
-}
118 110
 
119
-@keyframes to-right{
120
-    from{
121
-        transform: translateX(0%);
122
-    }
123
-    to{
124
-        transform: translateX(100%);
125
-    }
126
-}
127
-
128
-@media (prefers-reduced-motion: no-preference) {
129
-    @supports (animation-timeline: scroll()) {
130
-        .part.left {
131
-            animation: to-left linear both;
132
-            animation-timeline: scroll();
133
-            animation-range-end: 4%;
134
-        }
135
-
136
-        .part.right {
137
-            animation: to-right linear both;
138
-            animation-timeline: scroll();
139
-            animation-range-end: 4%;
140
-        }
141
-    }
142
-}
143 111
 
144 112
 
145 113
 @keyframes pulsIn {

+ 74
- 30
resources/js/app.js View File

@@ -7,6 +7,7 @@ import '@fortawesome/fontawesome-free/css/all.min.css';
7 7
 document.addEventListener('DOMContentLoaded', function () {
8 8
 
9 9
     imageLoading()
10
+    scrollOpenCover();
10 11
     reset() // reset everrything to ensure smooth
11 12
     sessionStorage.setItem("initial-load", "true"); // will be used by click event
12 13
 
@@ -37,12 +38,12 @@ document.addEventListener('click', function () {
37 38
         }, 600)
38 39
     }
39 40
 
40
-    setTimeout(()=>{
41
+    setTimeout(() => {
41 42
         eventCountdown();
42 43
         let petalOverlay = document.getElementById("petalOverlay");
43 44
         petalOverlay.classList.remove("hidden");
44 45
 
45
-    },5000)
46
+    }, 5000)
46 47
 
47 48
 });
48 49
 
@@ -103,6 +104,49 @@ function imageLoading() {
103 104
     checkAllImagesLoaded();
104 105
 }
105 106
 
107
+// enable open close cover
108
+function scrollOpenCover() {
109
+    var partLeftPos = 0;
110
+    var partRightPos = 0;
111
+
112
+    function updatePositions() {
113
+        var distance = $(window).scrollTop() * 2;
114
+        var left = partLeftPos - distance;
115
+        var right = partRightPos - distance;
116
+
117
+        $('.left').css('left', left + "px");
118
+        $('.right').css('right', right + "px");
119
+
120
+        //Calculate boundaries
121
+        var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
122
+
123
+        //Check if both parts are completely off-screen
124
+        var isLeftOffScreen = leftPartRightEdge <= 0;
125
+
126
+        //Toggle visibility and z-index
127
+        if (isLeftOffScreen && left < 0) {
128
+            $('.parent').removeClass('z-30');
129
+        } else {
130
+            $('.parent').addClass('z-30');
131
+        }
132
+    }
133
+
134
+    //Initial positions update
135
+    updatePositions();
136
+
137
+    //Listen to scroll events using requestAnimationFrame for smooth animation
138
+    var ticking = false;
139
+    $(window).scroll(function () {
140
+        if (!ticking) {
141
+            window.requestAnimationFrame(function () {
142
+                updatePositions();
143
+                ticking = false;
144
+            });
145
+        }
146
+        ticking = true;
147
+    });
148
+}
149
+
106 150
 function reset() {
107 151
 
108 152
     // reset to top
@@ -115,7 +159,7 @@ function reset() {
115 159
     }, 100)
116 160
 }
117 161
 
118
-function playMusic(){
162
+function playMusic() {
119 163
     var audioElement = document.getElementById('player');
120 164
     var hasPlayed = false;
121 165
     if (!hasPlayed) {
@@ -123,10 +167,10 @@ function playMusic(){
123 167
         var playPromise = audioElement.play();
124 168
 
125 169
         if (playPromise !== undefined) {
126
-            playPromise.then(function() {
170
+            playPromise.then(function () {
127 171
                 // Automatic playback started!
128 172
                 hasPlayed = true; // Prevent further attempts to play
129
-            }).catch(function(error) {
173
+            }).catch(function (error) {
130 174
                 // Automatic playback failed.
131 175
                 console.log('Autoplay failed: ' + error);
132 176
             });
@@ -134,28 +178,28 @@ function playMusic(){
134 178
     }
135 179
 }
136 180
 
137
-function eventCountdown(){
181
+function eventCountdown() {
138 182
 
139
-//Countdown date (adjust this date to your desired countdown target)
140
-const countdownDate = new Date('2024-08-17T11:00:00').getTime();
183
+    //Countdown date (adjust this date to your desired countdown target)
184
+    const countdownDate = new Date('2024-08-17T11:00:00').getTime();
141 185
 
142
-//Update the countdown every second
143
-const countdownElement = document.getElementById('countdown');
144
-const countdownTimer = setInterval(() => {
145
-    //Get the current date and time
146
-    const now = new Date().getTime();
186
+    //Update the countdown every second
187
+    const countdownElement = document.getElementById('countdown');
188
+    const countdownTimer = setInterval(() => {
189
+        //Get the current date and time
190
+        const now = new Date().getTime();
147 191
 
148
-    //Calculate the time remaining
149
-    const distance = countdownDate - now;
192
+        //Calculate the time remaining
193
+        const distance = countdownDate - now;
150 194
 
151
-    //Calculate days, hours, minutes, and seconds
152
-    const days = Math.floor(distance / (1000 * 60 * 60 * 24));
153
-    const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
154
-    const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
155
-    const seconds = Math.floor((distance % (1000 * 60)) / 1000);
195
+        //Calculate days, hours, minutes, and seconds
196
+        const days = Math.floor(distance / (1000 * 60 * 60 * 24));
197
+        const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
198
+        const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
199
+        const seconds = Math.floor((distance % (1000 * 60)) / 1000);
156 200
 
157
-    //Format the countdown into a string
158
-    const countdownHTML = `
201
+        //Format the countdown into a string
202
+        const countdownHTML = `
159 203
         <div class="flex flex-col">
160 204
             <div class="flex gap-8 justify-center">
161 205
                 <div class="font-medium text-gray-500">${days}</div>
@@ -175,13 +219,13 @@ const countdownTimer = setInterval(() => {
175 219
         </div>
176 220
     `;
177 221
 
178
-    //Display the countdown in the element
179
-    countdownElement.innerHTML = countdownHTML;
222
+        //Display the countdown in the element
223
+        countdownElement.innerHTML = countdownHTML;
180 224
 
181
-    //If the countdown is over, clear the timer and display a message
182
-    if (distance < 0) {
183
-        clearInterval(countdownTimer);
184
-        countdownElement.innerHTML = 'Majlis berlangsung';
185
-    }
186
-}, 1000); // Update every second (1000 milliseconds)
225
+        //If the countdown is over, clear the timer and display a message
226
+        if (distance < 0) {
227
+            clearInterval(countdownTimer);
228
+            countdownElement.innerHTML = 'Majlis berlangsung';
229
+        }
230
+    }, 1000); // Update every second (1000 milliseconds)
187 231
 }

Loading…
Cancel
Save