Wedding Invitation
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

app.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. import './bootstrap';
  2. // resources/js/app.js
  3. import '@fortawesome/fontawesome-free/css/all.min.css';
  4. // Countdown date (adjust this date to your desired countdown target)
  5. const countdownDate = new Date('2024-08-17T11:00:00').getTime();
  6. // Update the countdown every second
  7. const countdownElement = document.getElementById('countdown');
  8. const countdownTimer = setInterval(() => {
  9. // Get the current date and time
  10. const now = new Date().getTime();
  11. // Calculate the time remaining
  12. const distance = countdownDate - now;
  13. // Calculate days, hours, minutes, and seconds
  14. const days = Math.floor(distance / (1000 * 60 * 60 * 24));
  15. const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  16. const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  17. const seconds = Math.floor((distance % (1000 * 60)) / 1000);
  18. // Format the countdown into a string
  19. const countdownHTML = `
  20. <div class="flex flex-col">
  21. <div class="flex gap-8 justify-center">
  22. <div class="font-medium text-gray-500">${days}</div>
  23. <div class="font-medium text-gray-500">:</div>
  24. <div class="font-medium text-gray-500">${hours.toString().padStart(2, '0')}</div>
  25. <div class="font-medium text-gray-500">:</div>
  26. <div class="font-medium text-gray-500">${minutes.toString().padStart(2, '0')}</div>
  27. <div class="font-medium text-gray-500">:</div>
  28. <div class="font-medium text-gray-500">${seconds.toString().padStart(2, '0')}</div>
  29. </div>
  30. <div class="flex gap-14 justify-center">
  31. <div class="font-medium text-gray-600">Hari</div>
  32. <div class="font-medium text-gray-600">Jam</div>
  33. <div class="font-medium text-gray-600">Minit</div>
  34. <div class="font-medium text-gray-600">Saat</div>
  35. </div>
  36. </div>
  37. `;
  38. // Display the countdown in the element
  39. countdownElement.innerHTML = countdownHTML;
  40. // If the countdown is over, clear the timer and display a message
  41. if (distance < 0) {
  42. clearInterval(countdownTimer);
  43. countdownElement.innerHTML = 'Majlis berlangsung';
  44. }
  45. }, 1000); // Update every second (1000 milliseconds)
  46. $(document).ready(function() {
  47. var partLeftPos = 0;
  48. var partRightPos = 0;
  49. var audioElement = document.getElementById('player');
  50. var hasPlayed = false;
  51. var scrollCount = 0;
  52. var maxScrolls = 8;
  53. var scrollInterval = 200;
  54. var scrollAmount = window.innerHeight / 6;
  55. // Function to handle smooth scrolling
  56. function smoothScroll() {
  57. if (!hasPlayed) {
  58. playAudio();
  59. scrollCount++;
  60. if (scrollCount >= maxScrolls) {
  61. playAudio();
  62. } else {
  63. var start = window.pageYOffset;
  64. var target = start + scrollAmount;
  65. var screenWidth = window.innerWidth;
  66. var duration;
  67. if (screenWidth < 600) {
  68. duration = 5000; // Smaller screen
  69. } else if (screenWidth < 1200) {
  70. duration = 12000; // Medium screen
  71. } else {
  72. duration = 15000; // Larger screen
  73. }
  74. var startTime = null;
  75. function scrollStep(timestamp) {
  76. if (!startTime) startTime = timestamp;
  77. var progress = timestamp - startTime;
  78. var currentPosition = start + ((target - start) * (progress / duration));
  79. window.scrollTo(0, currentPosition);
  80. if (progress < duration) {
  81. requestAnimationFrame(scrollStep);
  82. } else {
  83. setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
  84. }
  85. }
  86. requestAnimationFrame(scrollStep);
  87. }
  88. }
  89. }
  90. // Function to play audio (if not already played)
  91. function playAudio() {
  92. if (!hasPlayed) {
  93. var playPromise = audioElement.play();
  94. if (playPromise !== undefined) {
  95. playPromise.then(function() {
  96. hasPlayed = true;
  97. }).catch(function(error) {
  98. console.log('Autoplay failed: ' + error);
  99. });
  100. }
  101. }
  102. }
  103. // jQuery scroll event handling
  104. $(window).scroll(function() {
  105. var distance = $(this).scrollTop() * 2;
  106. var left = partLeftPos - distance;
  107. var right = partRightPos - distance;
  108. $('.left').css('left', left + "px");
  109. $('.right').css('right', right + "px");
  110. var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
  111. var isLeftOffScreen = leftPartRightEdge <= 0;
  112. if (isLeftOffScreen && left < 0) {
  113. $('.parent').removeClass('z-30');
  114. } else {
  115. $('.parent').addClass('z-30');
  116. }
  117. });
  118. // Initially check visibility on page load
  119. $(window).trigger('scroll');
  120. // Event listener for click to show overlay after a delay
  121. document.addEventListener('click', function() {
  122. setTimeout(function() {
  123. document.getElementById('petalOverlay').style.display = 'block';
  124. }, 1000); // Delay of 1 second (1000 milliseconds)
  125. });
  126. // Event listener for scroll to reset audio and overlay if scrolled to top
  127. window.addEventListener('scroll', function() {
  128. if (window.pageYOffset === 0) {
  129. audioElement.pause();
  130. document.getElementById('petalOverlay').style.display = 'none';
  131. hasPlayed = false;
  132. document.body.classList.add('no-scroll');
  133. }
  134. });
  135. });
  136. // $(function() {
  137. // var partLeftPos = 0;
  138. // var partRightPos = 0;
  139. // $(window).scroll(function(event) {
  140. // var distance = $(this).scrollTop() * 2;
  141. // var left = partLeftPos - distance;
  142. // var right = partRightPos - distance;
  143. // $('.left').css('left', left + "px");
  144. // $('.right').css('right', right + "px");
  145. // // Calculate boundaries
  146. // var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
  147. // // Check if both parts are completely off-screen
  148. // var isLeftOffScreen = leftPartRightEdge <= 0;
  149. // // Toggle visibility and z-index
  150. // if (isLeftOffScreen && left < 0) {
  151. // $('.parent').removeClass(['z-30']);
  152. // } else {
  153. // $('.parent').addClass(['z-30']);
  154. // }
  155. // });
  156. // // Initially check visibility on page load
  157. // $(window).trigger('scroll');
  158. // });
  159. // document.addEventListener('click', function () {
  160. // setTimeout(function () {
  161. // document.getElementById('petalOverlay').style.display = 'block';
  162. // }, 1000); // Delay of 1 second (1000 milliseconds)
  163. // });
  164. // document.addEventListener('DOMContentLoaded', function() {
  165. // var audioElement = document.getElementById('player');
  166. // var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
  167. // var scrollCount = 0;
  168. // var maxScrolls = 8;
  169. // var scrollInterval = 200; // Time in milliseconds between each scroll
  170. // var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
  171. // function playAudio() {
  172. // if (!hasPlayed) {
  173. // console.log('play')
  174. // var playPromise = audioElement.play();
  175. // if (playPromise !== undefined) {
  176. // playPromise.then(function() {
  177. // // Automatic playback started!
  178. // hasPlayed = true; // Prevent further attempts to play
  179. // }).catch(function(error) {
  180. // // Automatic playback failed.
  181. // console.log('Autoplay failed: ' + error);
  182. // });
  183. // }
  184. // }
  185. // }
  186. // function smoothScroll() {
  187. // if (!hasPlayed) {
  188. // playAudio();
  189. // scrollCount++;
  190. // if (scrollCount >= maxScrolls) {
  191. // playAudio();
  192. // } else {
  193. // var start = window.pageYOffset;
  194. // var target = start + scrollAmount;
  195. // // Set duration based on screen size
  196. // var screenWidth = window.innerWidth;
  197. // var duration;
  198. // if (screenWidth < 600) {
  199. // duration = 5000; // Smaller screen
  200. // } else if (screenWidth < 1200) {
  201. // duration = 12000; // Medium screen
  202. // } else {
  203. // duration = 15000; // Larger screen
  204. // }
  205. // var startTime = null;
  206. // function scrollStep(timestamp) {
  207. // if (!startTime) startTime = timestamp;
  208. // var progress = timestamp - startTime;
  209. // var currentPosition = start + ((target - start) * (progress / duration));
  210. // window.scrollTo(0, currentPosition);
  211. // if (progress < duration) {
  212. // requestAnimationFrame(scrollStep);
  213. // } else {
  214. // setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
  215. // }
  216. // }
  217. // requestAnimationFrame(scrollStep);
  218. // }
  219. // }
  220. // }
  221. // function playOnly() {
  222. // if (!hasPlayed) {
  223. // playAudio();
  224. // scrollCount++;
  225. // if (scrollCount >= maxScrolls) {
  226. // playAudio();
  227. // } else {
  228. // setTimeout(playOnly, scrollInterval);
  229. // }
  230. // }
  231. // }
  232. // function handleInteraction() {
  233. // document.body.classList.remove('no-scroll'); // Enable scrolling
  234. // setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
  235. // }
  236. // // Listen for click or touch event to start auto-scrolling
  237. // window.addEventListener('click', handleInteraction);
  238. // window.addEventListener('scroll', function() {
  239. // if (window.pageYOffset === 0) {
  240. // audioElement.pause();
  241. // document.getElementById('petalOverlay').style.display = 'none';
  242. // hasPlayed = false; // Reset to allow replay
  243. // document.body.classList.add('no-scroll');
  244. // }
  245. // });
  246. // // Intersection Observer for fading in elements
  247. // const observerOptions = {
  248. // root: null,
  249. // rootMargin: '0px',
  250. // threshold: 0.1
  251. // };
  252. // const observer = new IntersectionObserver((entries, observer) => {
  253. // entries.forEach(entry => {
  254. // if (entry.isIntersecting) {
  255. // entry.target.classList.add('fade-in');
  256. // observer.unobserve(entry.target);
  257. // }
  258. // });
  259. // }, observerOptions);
  260. // document.querySelectorAll('.fade-element').forEach(element => {
  261. // observer.observe(element);
  262. // });
  263. // });