Wedding Invitation
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import './bootstrap';
  2. //import '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.addEventListener('DOMContentLoaded', function () {
  47. imageLoading()
  48. scrollOpenCover()
  49. reset() // reset everrything to ensure smooth
  50. sessionStorage.setItem("initial-load", "true"); // will be used by click event
  51. });
  52. document.addEventListener('click', function () {
  53. let initLoad = sessionStorage.getItem("initial-load")
  54. // parts is intro cover
  55. let parts = document.getElementsByClassName("part");
  56. for (let part of parts) {
  57. part.classList.add("shadow-lg")
  58. }
  59. let body = document.querySelector("body");
  60. body.classList.remove("no-scroll");
  61. // the intro - only done once and
  62. if (initLoad == "true") {
  63. playMusic();
  64. sessionStorage.removeItem("initial-load")
  65. // delay timer to have that umpph feels my G
  66. setTimeout(() => {
  67. // smooth scroll only happen for first render
  68. smoothScrollBy(100, 3500);
  69. }, 500)
  70. }
  71. });
  72. function smoothScrollBy(distance, duration) {
  73. const start = window.pageYOffset;
  74. const startTime = performance.now();
  75. function scroll() {
  76. const now = performance.now();
  77. const time = Math.min(1, (now - startTime) / duration);
  78. const timeFunction = time * (2 - time); // Ease out effect
  79. window.scrollTo(0, start + timeFunction * distance);
  80. if (time < 1) {
  81. requestAnimationFrame(scroll);
  82. }
  83. }
  84. requestAnimationFrame(scroll);
  85. }
  86. // enable open close cover
  87. function scrollOpenCover() {
  88. var partLeftPos = 0;
  89. var partRightPos = 0;
  90. function updatePositions() {
  91. var distance = $(window).scrollTop() * 2;
  92. var left = partLeftPos - distance;
  93. var right = partRightPos - distance;
  94. $('.left').css('left', left + "px");
  95. $('.right').css('right', right + "px");
  96. //Calculate boundaries
  97. var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
  98. //Check if both parts are completely off-screen
  99. var isLeftOffScreen = leftPartRightEdge <= 0;
  100. //Toggle visibility and z-index
  101. if (isLeftOffScreen && left < 0) {
  102. $('.parent').removeClass('z-30');
  103. } else {
  104. $('.parent').addClass('z-30');
  105. }
  106. }
  107. //Initial positions update
  108. updatePositions();
  109. //Listen to scroll events using requestAnimationFrame for smooth animation
  110. var ticking = false;
  111. $(window).scroll(function () {
  112. if (!ticking) {
  113. window.requestAnimationFrame(function () {
  114. updatePositions();
  115. ticking = false;
  116. });
  117. }
  118. ticking = true;
  119. });
  120. }
  121. // to ensure all images is loaded before starting animation and gimmick
  122. function imageLoading() {
  123. const images = document.querySelectorAll("img");
  124. let loadedCount = 0;
  125. const totalImages = images.length;
  126. images.forEach(image => {
  127. if (image.complete) {
  128. loadedCount++;
  129. } else {
  130. image.addEventListener("load", () => {
  131. loadedCount++;
  132. checkAllImagesLoaded();
  133. });
  134. image.addEventListener("error", () => {
  135. loadedCount++;
  136. checkAllImagesLoaded();
  137. });
  138. }
  139. });
  140. function checkAllImagesLoaded() {
  141. if (loadedCount === totalImages) {
  142. let loading = document.getElementById("loading");
  143. loading.remove();
  144. // parts is intro cover
  145. let parts = document.getElementsByClassName("part");
  146. for (let part of parts) {
  147. part.classList.remove("hidden")
  148. }
  149. }
  150. }
  151. //somehow the server work so fast, script doesn't have much time to set the load eventlistener
  152. //thus we check here, to ensure checkAllImagesLoaded run
  153. checkAllImagesLoaded()
  154. }
  155. function reset() {
  156. // reset to top
  157. let body = document.querySelector("body");
  158. body.classList.remove("no-scroll");
  159. window.scrollTo(0, 0);
  160. setTimeout(() => {
  161. body.classList.add("no-scroll");
  162. }, 500)
  163. }
  164. function playMusic(){
  165. var audioElement = document.getElementById('player');
  166. var hasPlayed = false;
  167. if (!hasPlayed) {
  168. console.log('play')
  169. var playPromise = audioElement.play();
  170. if (playPromise !== undefined) {
  171. playPromise.then(function() {
  172. // Automatic playback started!
  173. hasPlayed = true; // Prevent further attempts to play
  174. }).catch(function(error) {
  175. // Automatic playback failed.
  176. console.log('Autoplay failed: ' + error);
  177. });
  178. }
  179. }
  180. }