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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import './bootstrap';
  2. //import 'resources/js/app.js';
  3. import '@fortawesome/fontawesome-free/css/all.min.css';
  4. document.addEventListener('DOMContentLoaded', function () {
  5. imageLoading()
  6. reset() // reset everrything to ensure smooth
  7. sessionStorage.setItem("initial-load", "true"); // will be used by click event
  8. });
  9. document.addEventListener('click', function () {
  10. let initLoad = sessionStorage.getItem("initial-load")
  11. // parts is intro cover
  12. let parts = document.getElementsByClassName("part");
  13. for (let part of parts) {
  14. part.classList.add("shadow-lg")
  15. }
  16. let body = document.querySelector("body");
  17. body.classList.remove("no-scroll");
  18. // the intro - only done once and
  19. if (initLoad == "true") {
  20. playMusic();
  21. sessionStorage.removeItem("initial-load")
  22. // delay timer to have that umpph feels my G
  23. setTimeout(() => {
  24. // smooth scroll only happen for first render
  25. smoothScrollBy(100, 3500);
  26. }, 600)
  27. }
  28. setTimeout(()=>{
  29. eventCountdown();
  30. let petalOverlay = document.getElementById("petalOverlay");
  31. petalOverlay.classList.remove("hidden");
  32. },4000)
  33. });
  34. function smoothScrollBy(distance, duration) {
  35. const start = window.pageYOffset;
  36. const startTime = performance.now();
  37. function scroll() {
  38. const now = performance.now();
  39. const time = Math.min(1, (now - startTime) / duration);
  40. const timeFunction = time * (2 - time); // Ease out effect
  41. window.scrollTo(0, start + timeFunction * distance);
  42. if (time < 1) {
  43. requestAnimationFrame(scroll);
  44. }
  45. }
  46. requestAnimationFrame(scroll);
  47. }
  48. // to ensure all images is loaded before starting animation and gimmick
  49. function imageLoading() {
  50. const images = document.querySelectorAll("img");
  51. let loadedCount = 0;
  52. const totalImages = images.length;
  53. images.forEach(image => {
  54. if (image.complete) {
  55. loadedCount++;
  56. } else {
  57. image.addEventListener("load", () => {
  58. loadedCount++;
  59. checkAllImagesLoaded();
  60. });
  61. image.addEventListener("error", () => {
  62. loadedCount++;
  63. checkAllImagesLoaded();
  64. });
  65. }
  66. });
  67. function checkAllImagesLoaded() {
  68. if (loadedCount === totalImages) {
  69. let loading = document.getElementById("loading");
  70. loading.remove();
  71. // parts is intro cover
  72. let parts = document.getElementsByClassName("part");
  73. for (let part of parts) {
  74. part.classList.remove("hidden")
  75. }
  76. }
  77. }
  78. //somehow the server work so fast, script doesn't have much time to set the load eventlistener
  79. //thus we check here, to ensure checkAllImagesLoaded run
  80. checkAllImagesLoaded();
  81. }
  82. function reset() {
  83. // reset to top
  84. let body = document.querySelector("body");
  85. body.classList.remove("no-scroll");
  86. window.scrollTo(0, 0);
  87. setTimeout(() => {
  88. body.classList.add("no-scroll");
  89. }, 100)
  90. }
  91. function playMusic(){
  92. var audioElement = document.getElementById('player');
  93. var hasPlayed = false;
  94. if (!hasPlayed) {
  95. console.log('play')
  96. var playPromise = audioElement.play();
  97. if (playPromise !== undefined) {
  98. playPromise.then(function() {
  99. // Automatic playback started!
  100. hasPlayed = true; // Prevent further attempts to play
  101. }).catch(function(error) {
  102. // Automatic playback failed.
  103. console.log('Autoplay failed: ' + error);
  104. });
  105. }
  106. }
  107. }
  108. function eventCountdown(){
  109. //Countdown date (adjust this date to your desired countdown target)
  110. const countdownDate = new Date('2024-08-17T11:00:00').getTime();
  111. //Update the countdown every second
  112. const countdownElement = document.getElementById('countdown');
  113. const countdownTimer = setInterval(() => {
  114. //Get the current date and time
  115. const now = new Date().getTime();
  116. //Calculate the time remaining
  117. const distance = countdownDate - now;
  118. //Calculate days, hours, minutes, and seconds
  119. const days = Math.floor(distance / (1000 * 60 * 60 * 24));
  120. const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  121. const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  122. const seconds = Math.floor((distance % (1000 * 60)) / 1000);
  123. //Format the countdown into a string
  124. const countdownHTML = `
  125. <div class="flex flex-col">
  126. <div class="flex gap-8 justify-center">
  127. <div class="font-medium text-gray-500">${days}</div>
  128. <div class="font-medium text-gray-500">:</div>
  129. <div class="font-medium text-gray-500">${hours.toString().padStart(2, '0')}</div>
  130. <div class="font-medium text-gray-500">:</div>
  131. <div class="font-medium text-gray-500">${minutes.toString().padStart(2, '0')}</div>
  132. <div class="font-medium text-gray-500">:</div>
  133. <div class="font-medium text-gray-500">${seconds.toString().padStart(2, '0')}</div>
  134. </div>
  135. <div class="flex gap-14 justify-center">
  136. <div class="font-medium text-gray-600">Hari</div>
  137. <div class="font-medium text-gray-600">Jam</div>
  138. <div class="font-medium text-gray-600">Minit</div>
  139. <div class="font-medium text-gray-600">Saat</div>
  140. </div>
  141. </div>
  142. `;
  143. //Display the countdown in the element
  144. countdownElement.innerHTML = countdownHTML;
  145. //If the countdown is over, clear the timer and display a message
  146. if (distance < 0) {
  147. clearInterval(countdownTimer);
  148. countdownElement.innerHTML = 'Majlis berlangsung';
  149. }
  150. }, 1000); // Update every second (1000 milliseconds)
  151. }