|
@@ -1,27 +1,27 @@
|
1
|
1
|
import './bootstrap';
|
2
|
|
-// resources/js/app.js
|
|
2
|
+//import 'resources/js/app.js';
|
3
|
3
|
import '@fortawesome/fontawesome-free/css/all.min.css';
|
4
|
4
|
|
5
|
5
|
|
6
|
|
-// Countdown date (adjust this date to your desired countdown target)
|
|
6
|
+//Countdown date (adjust this date to your desired countdown target)
|
7
|
7
|
const countdownDate = new Date('2024-08-17T11:00:00').getTime();
|
8
|
8
|
|
9
|
|
-// Update the countdown every second
|
|
9
|
+//Update the countdown every second
|
10
|
10
|
const countdownElement = document.getElementById('countdown');
|
11
|
11
|
const countdownTimer = setInterval(() => {
|
12
|
|
- // Get the current date and time
|
|
12
|
+ //Get the current date and time
|
13
|
13
|
const now = new Date().getTime();
|
14
|
|
-
|
15
|
|
- // Calculate the time remaining
|
|
14
|
+
|
|
15
|
+ //Calculate the time remaining
|
16
|
16
|
const distance = countdownDate - now;
|
17
|
|
-
|
18
|
|
- // Calculate days, hours, minutes, and seconds
|
|
17
|
+
|
|
18
|
+ //Calculate days, hours, minutes, and seconds
|
19
|
19
|
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
|
20
|
20
|
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
21
|
21
|
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
|
22
|
22
|
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
|
23
|
|
-
|
24
|
|
- // Format the countdown into a string
|
|
23
|
+
|
|
24
|
+ //Format the countdown into a string
|
25
|
25
|
const countdownHTML = `
|
26
|
26
|
<div class="flex flex-col">
|
27
|
27
|
<div class="flex gap-8 justify-center">
|
|
@@ -41,18 +41,75 @@ const countdownTimer = setInterval(() => {
|
41
|
41
|
</div>
|
42
|
42
|
</div>
|
43
|
43
|
`;
|
44
|
|
-
|
45
|
|
- // Display the countdown in the element
|
|
44
|
+
|
|
45
|
+ //Display the countdown in the element
|
46
|
46
|
countdownElement.innerHTML = countdownHTML;
|
47
|
|
-
|
48
|
|
- // If the countdown is over, clear the timer and display a message
|
|
47
|
+
|
|
48
|
+ //If the countdown is over, clear the timer and display a message
|
49
|
49
|
if (distance < 0) {
|
50
|
50
|
clearInterval(countdownTimer);
|
51
|
51
|
countdownElement.innerHTML = 'Majlis berlangsung';
|
52
|
52
|
}
|
53
|
53
|
}, 1000); // Update every second (1000 milliseconds)
|
54
|
54
|
|
55
|
|
-$(function() {
|
|
55
|
+document.addEventListener('DOMContentLoaded', function () {
|
|
56
|
+ imageLoading()
|
|
57
|
+ scrollOpenCover()
|
|
58
|
+
|
|
59
|
+ reset() // reset everrything to ensure smooth
|
|
60
|
+ sessionStorage.setItem("initial-load", "true"); // will be used by click event
|
|
61
|
+
|
|
62
|
+});
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+document.addEventListener('click', function () {
|
|
66
|
+
|
|
67
|
+ let initLoad = sessionStorage.getItem("initial-load")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+ // parts is intro cover
|
|
71
|
+ let parts = document.getElementsByClassName("part");
|
|
72
|
+ for (let part of parts) {
|
|
73
|
+ part.classList.add("shadow-lg")
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ let body = document.querySelector("body");
|
|
77
|
+ body.classList.remove("no-scroll");
|
|
78
|
+
|
|
79
|
+ // the intro - only done once and
|
|
80
|
+ if (initLoad == "true") {
|
|
81
|
+ playMusic();
|
|
82
|
+ sessionStorage.removeItem("initial-load")
|
|
83
|
+ // delay timer to have that umpph feels my G
|
|
84
|
+ setTimeout(() => {
|
|
85
|
+ // smooth scroll only happen for first render
|
|
86
|
+ smoothScrollBy(100, 3500);
|
|
87
|
+ }, 500)
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+});
|
|
91
|
+
|
|
92
|
+function smoothScrollBy(distance, duration) {
|
|
93
|
+ const start = window.pageYOffset;
|
|
94
|
+ const startTime = performance.now();
|
|
95
|
+
|
|
96
|
+ function scroll() {
|
|
97
|
+ const now = performance.now();
|
|
98
|
+ const time = Math.min(1, (now - startTime) / duration);
|
|
99
|
+ const timeFunction = time * (2 - time); // Ease out effect
|
|
100
|
+ window.scrollTo(0, start + timeFunction * distance);
|
|
101
|
+
|
|
102
|
+ if (time < 1) {
|
|
103
|
+ requestAnimationFrame(scroll);
|
|
104
|
+ }
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ requestAnimationFrame(scroll);
|
|
108
|
+}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+// enable open close cover
|
|
112
|
+function scrollOpenCover() {
|
56
|
113
|
var partLeftPos = 0;
|
57
|
114
|
var partRightPos = 0;
|
58
|
115
|
|
|
@@ -64,13 +121,13 @@ $(function() {
|
64
|
121
|
$('.left').css('left', left + "px");
|
65
|
122
|
$('.right').css('right', right + "px");
|
66
|
123
|
|
67
|
|
- // Calculate boundaries
|
|
124
|
+ //Calculate boundaries
|
68
|
125
|
var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
|
69
|
126
|
|
70
|
|
- // Check if both parts are completely off-screen
|
|
127
|
+ //Check if both parts are completely off-screen
|
71
|
128
|
var isLeftOffScreen = leftPartRightEdge <= 0;
|
72
|
129
|
|
73
|
|
- // Toggle visibility and z-index
|
|
130
|
+ //Toggle visibility and z-index
|
74
|
131
|
if (isLeftOffScreen && left < 0) {
|
75
|
132
|
$('.parent').removeClass('z-30');
|
76
|
133
|
} else {
|
|
@@ -78,138 +135,83 @@ $(function() {
|
78
|
135
|
}
|
79
|
136
|
}
|
80
|
137
|
|
81
|
|
- // Initial positions update
|
|
138
|
+ //Initial positions update
|
82
|
139
|
updatePositions();
|
83
|
140
|
|
84
|
|
- // Listen to scroll events using requestAnimationFrame for smooth animation
|
|
141
|
+ //Listen to scroll events using requestAnimationFrame for smooth animation
|
85
|
142
|
var ticking = false;
|
86
|
|
- $(window).scroll(function() {
|
|
143
|
+ $(window).scroll(function () {
|
87
|
144
|
if (!ticking) {
|
88
|
|
- window.requestAnimationFrame(function() {
|
|
145
|
+ window.requestAnimationFrame(function () {
|
89
|
146
|
updatePositions();
|
90
|
147
|
ticking = false;
|
91
|
148
|
});
|
92
|
149
|
}
|
93
|
150
|
ticking = true;
|
94
|
151
|
});
|
95
|
|
-});
|
|
152
|
+}
|
96
|
153
|
|
|
154
|
+// to ensure all images is loaded before starting animation and gimmick
|
|
155
|
+function imageLoading() {
|
|
156
|
+ const images = document.querySelectorAll("img");
|
|
157
|
+ let loadedCount = 0;
|
|
158
|
+ const totalImages = images.length;
|
97
|
159
|
|
98
|
|
-document.addEventListener('click', function () {
|
99
|
|
- setTimeout(function () {
|
100
|
|
- document.getElementById('petalOverlay').style.display = 'block';
|
101
|
|
- }, 1000); // Delay of 1 second (1000 milliseconds)
|
102
|
|
-});
|
103
|
|
-
|
104
|
|
-document.addEventListener('DOMContentLoaded', function() {
|
105
|
|
- var audioElement = document.getElementById('player');
|
106
|
|
- var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
|
107
|
|
- var scrollCount = 0;
|
108
|
|
- var maxScrolls = 8;
|
109
|
|
- var scrollInterval = 200; // Time in milliseconds between each scroll
|
110
|
|
- var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
|
111
|
|
-
|
112
|
|
- function playAudio() {
|
113
|
|
- if (!hasPlayed) {
|
114
|
|
- console.log('play')
|
115
|
|
- var playPromise = audioElement.play();
|
116
|
|
-
|
117
|
|
- if (playPromise !== undefined) {
|
118
|
|
- playPromise.then(function() {
|
119
|
|
- // Automatic playback started!
|
120
|
|
- hasPlayed = true; // Prevent further attempts to play
|
121
|
|
- }).catch(function(error) {
|
122
|
|
- // Automatic playback failed.
|
123
|
|
- console.log('Autoplay failed: ' + error);
|
124
|
|
- });
|
125
|
|
- }
|
|
160
|
+ images.forEach(image => {
|
|
161
|
+ if (image.complete) {
|
|
162
|
+ loadedCount++;
|
|
163
|
+ } else {
|
|
164
|
+ image.addEventListener("load", () => {
|
|
165
|
+ loadedCount++;
|
|
166
|
+ checkAllImagesLoaded();
|
|
167
|
+ });
|
|
168
|
+ image.addEventListener("error", () => {
|
|
169
|
+ loadedCount++;
|
|
170
|
+ checkAllImagesLoaded();
|
|
171
|
+ });
|
126
|
172
|
}
|
127
|
|
- }
|
|
173
|
+ });
|
128
|
174
|
|
129
|
|
- function smoothScroll() {
|
130
|
|
- if (!hasPlayed) {
|
131
|
|
- playAudio();
|
132
|
|
- scrollCount++;
|
133
|
|
- if (scrollCount >= maxScrolls) {
|
134
|
|
- playAudio();
|
135
|
|
- } else {
|
136
|
|
- var start = window.pageYOffset;
|
137
|
|
- var target = start + scrollAmount;
|
138
|
|
- // Set duration based on screen size
|
139
|
|
- var screenWidth = window.innerWidth;
|
140
|
|
- var duration;
|
141
|
|
- if (screenWidth < 600) {
|
142
|
|
- duration = 8000; // Smaller screen
|
143
|
|
- } else if (screenWidth < 1200) {
|
144
|
|
- duration = 12000; // Medium screen
|
145
|
|
- } else {
|
146
|
|
- duration = 15000; // Larger screen
|
147
|
|
- }
|
148
|
|
- var startTime = null;
|
149
|
|
-
|
150
|
|
- function scrollStep(timestamp) {
|
151
|
|
- if (!startTime) startTime = timestamp;
|
152
|
|
- var progress = timestamp - startTime;
|
153
|
|
- var currentPosition = start + ((target - start) * (progress / duration));
|
154
|
|
- window.scrollTo(0, currentPosition);
|
155
|
|
- if (progress < duration) {
|
156
|
|
- requestAnimationFrame(scrollStep);
|
157
|
|
- } else {
|
158
|
|
- setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
|
159
|
|
- }
|
160
|
|
- }
|
161
|
|
-
|
162
|
|
- requestAnimationFrame(scrollStep);
|
|
175
|
+ function checkAllImagesLoaded() {
|
|
176
|
+ if (loadedCount === totalImages) {
|
|
177
|
+ let loading = document.getElementById("loading");
|
|
178
|
+ loading.remove();
|
|
179
|
+ // parts is intro cover
|
|
180
|
+ let parts = document.getElementsByClassName("part");
|
|
181
|
+ for (let part of parts) {
|
|
182
|
+ part.classList.remove("hidden")
|
163
|
183
|
}
|
164
|
|
- }
|
165
|
|
- }
|
166
|
184
|
|
167
|
|
- function playOnly() {
|
168
|
|
- if (!hasPlayed) {
|
169
|
|
- playAudio();
|
170
|
|
- scrollCount++;
|
171
|
|
- if (scrollCount >= maxScrolls) {
|
172
|
|
- playAudio();
|
173
|
|
- } else {
|
174
|
|
- setTimeout(playOnly, scrollInterval);
|
175
|
|
- }
|
176
|
185
|
}
|
177
|
186
|
}
|
|
187
|
+}
|
178
|
188
|
|
179
|
|
- function handleInteraction() {
|
180
|
|
- document.body.classList.remove('no-scroll'); // Enable scrolling
|
181
|
|
- setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
|
182
|
|
- }
|
|
189
|
+function reset() {
|
|
190
|
+ // reset to top
|
|
191
|
+ let body = document.querySelector("body");
|
|
192
|
+ body.classList.remove("no-scroll");
|
|
193
|
+ window.scrollTo(0, 0);
|
183
|
194
|
|
184
|
|
- // Listen for click or touch event to start auto-scrolling
|
185
|
|
- window.addEventListener('click', handleInteraction);
|
|
195
|
+ setTimeout(() => {
|
|
196
|
+ body.classList.add("no-scroll");
|
|
197
|
+ }, 500)
|
|
198
|
+}
|
186
|
199
|
|
187
|
|
- window.addEventListener('scroll', function() {
|
188
|
|
- if (window.pageYOffset === 0) {
|
189
|
|
- audioElement.pause();
|
190
|
|
- document.getElementById('petalOverlay').style.display = 'none';
|
191
|
|
- hasPlayed = false; // Reset to allow replay
|
192
|
|
- document.body.classList.add('no-scroll');
|
|
200
|
+function playMusic(){
|
|
201
|
+ var audioElement = document.getElementById('player');
|
|
202
|
+ var hasPlayed = false;
|
|
203
|
+ if (!hasPlayed) {
|
|
204
|
+ console.log('play')
|
|
205
|
+ var playPromise = audioElement.play();
|
|
206
|
+
|
|
207
|
+ if (playPromise !== undefined) {
|
|
208
|
+ playPromise.then(function() {
|
|
209
|
+ // Automatic playback started!
|
|
210
|
+ hasPlayed = true; // Prevent further attempts to play
|
|
211
|
+ }).catch(function(error) {
|
|
212
|
+ // Automatic playback failed.
|
|
213
|
+ console.log('Autoplay failed: ' + error);
|
|
214
|
+ });
|
193
|
215
|
}
|
194
|
|
- });
|
195
|
|
-
|
196
|
|
- // Intersection Observer for fading in elements
|
197
|
|
- const observerOptions = {
|
198
|
|
- root: null,
|
199
|
|
- rootMargin: '0px',
|
200
|
|
- threshold: 0.1
|
201
|
|
- };
|
202
|
|
-
|
203
|
|
- const observer = new IntersectionObserver((entries, observer) => {
|
204
|
|
- entries.forEach(entry => {
|
205
|
|
- if (entry.isIntersecting) {
|
206
|
|
- entry.target.classList.add('fade-in');
|
207
|
|
- observer.unobserve(entry.target);
|
208
|
|
- }
|
209
|
|
- });
|
210
|
|
- }, observerOptions);
|
211
|
|
-
|
212
|
|
- document.querySelectorAll('.fade-element').forEach(element => {
|
213
|
|
- observer.observe(element);
|
214
|
|
- });
|
215
|
|
-});
|
|
216
|
+ }
|
|
217
|
+}
|