Wedding Invitation
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

app.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. reset() // reset everrything to ensure smooth
  49. sessionStorage.setItem("initial-load", "true"); // will be used by click event
  50. });
  51. document.addEventListener('click', function () {
  52. let initLoad = sessionStorage.getItem("initial-load")
  53. // parts is intro cover
  54. let parts = document.getElementsByClassName("part");
  55. for (let part of parts) {
  56. part.classList.add("shadow-lg")
  57. }
  58. let body = document.querySelector("body");
  59. body.classList.remove("no-scroll");
  60. // the intro - only done once and
  61. if (initLoad == "true") {
  62. playMusic();
  63. sessionStorage.removeItem("initial-load")
  64. // delay timer to have that umpph feels my G
  65. setTimeout(() => {
  66. // smooth scroll only happen for first render
  67. smoothScrollBy(100, 3500);
  68. }, 500)
  69. }
  70. });
  71. function smoothScrollBy(distance, duration) {
  72. const start = window.pageYOffset;
  73. const startTime = performance.now();
  74. function scroll() {
  75. const now = performance.now();
  76. const time = Math.min(1, (now - startTime) / duration);
  77. const timeFunction = time * (2 - time); // Ease out effect
  78. window.scrollTo(0, start + timeFunction * distance);
  79. if (time < 1) {
  80. requestAnimationFrame(scroll);
  81. }
  82. }
  83. requestAnimationFrame(scroll);
  84. }
  85. // to ensure all images is loaded before starting animation and gimmick
  86. function imageLoading() {
  87. const images = document.querySelectorAll("img");
  88. let loadedCount = 0;
  89. const totalImages = images.length;
  90. images.forEach(image => {
  91. if (image.complete) {
  92. loadedCount++;
  93. } else {
  94. image.addEventListener("load", () => {
  95. loadedCount++;
  96. checkAllImagesLoaded();
  97. });
  98. image.addEventListener("error", () => {
  99. loadedCount++;
  100. checkAllImagesLoaded();
  101. });
  102. }
  103. });
  104. function checkAllImagesLoaded() {
  105. if (loadedCount === totalImages) {
  106. let loading = document.getElementById("loading");
  107. loading.remove();
  108. // parts is intro cover
  109. let parts = document.getElementsByClassName("part");
  110. for (let part of parts) {
  111. part.classList.remove("hidden")
  112. }
  113. }
  114. }
  115. //somehow the server work so fast, script doesn't have much time to set the load eventlistener
  116. //thus we check here, to ensure checkAllImagesLoaded run
  117. checkAllImagesLoaded();
  118. }
  119. function reset() {
  120. // reset to top
  121. let body = document.querySelector("body");
  122. body.classList.remove("no-scroll");
  123. window.scrollTo(0, 0);
  124. setTimeout(() => {
  125. body.classList.add("no-scroll");
  126. }, 500)
  127. }
  128. function playMusic(){
  129. var audioElement = document.getElementById('player');
  130. var hasPlayed = false;
  131. if (!hasPlayed) {
  132. console.log('play')
  133. var playPromise = audioElement.play();
  134. if (playPromise !== undefined) {
  135. playPromise.then(function() {
  136. // Automatic playback started!
  137. hasPlayed = true; // Prevent further attempts to play
  138. }).catch(function(error) {
  139. // Automatic playback failed.
  140. console.log('Autoplay failed: ' + error);
  141. });
  142. }
  143. }
  144. }