Wedding Invitation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. }
  152. function reset() {
  153. // reset to top
  154. let body = document.querySelector("body");
  155. body.classList.remove("no-scroll");
  156. window.scrollTo(0, 0);
  157. setTimeout(() => {
  158. body.classList.add("no-scroll");
  159. }, 500)
  160. }
  161. function playMusic(){
  162. var audioElement = document.getElementById('player');
  163. var hasPlayed = false;
  164. if (!hasPlayed) {
  165. console.log('play')
  166. var playPromise = audioElement.play();
  167. if (playPromise !== undefined) {
  168. playPromise.then(function() {
  169. // Automatic playback started!
  170. hasPlayed = true; // Prevent further attempts to play
  171. }).catch(function(error) {
  172. // Automatic playback failed.
  173. console.log('Autoplay failed: ' + error);
  174. });
  175. }
  176. }
  177. }