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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. scrollOpenCover();
  7. reset() // reset everrything to ensure smooth
  8. sessionStorage.setItem("initial-load", "true"); // will be used by click event
  9. let rsvpBtn = document.getElementById("rsvp-button");
  10. rsvpBtn.addEventListener('click', function(){
  11. this.classList.remove("animate__flash");
  12. })
  13. let scrollerInd = document.getElementById("scroller");
  14. setTimeout(()=>{
  15. window.addEventListener('scroll', function(){
  16. scrollerInd.remove();
  17. })
  18. },1000)
  19. });
  20. document.addEventListener('click', function () {
  21. let initLoad = sessionStorage.getItem("initial-load")
  22. let pointer = document.getElementById("pointer")
  23. if(pointer) pointer.remove()
  24. // parts is intro cover
  25. let parts = document.getElementsByClassName("part");
  26. for (let part of parts) {
  27. part.classList.add("shadow-lg")
  28. }
  29. // the intro - only done once and
  30. if (initLoad == "true") {
  31. playMusic();
  32. let leftCover = document.querySelector(".dummy-cover .left-dummy");
  33. let rightCover = document.querySelector(".dummy-cover .right-dummy");
  34. leftCover.classList.add("to-left-animation")
  35. rightCover.classList.add("to-right-animation")
  36. setTimeout(()=>{
  37. //dummy-cover
  38. let parts = document.querySelectorAll(".dummy-cover .part");
  39. for (let part of parts) {
  40. part.remove("hidden")
  41. }
  42. let body = document.querySelector("body");
  43. body.classList.remove("no-scroll");
  44. },2500)
  45. sessionStorage.removeItem("initial-load")
  46. }
  47. setTimeout(() => {
  48. eventCountdown();
  49. let petalOverlay = document.getElementById("petalOverlay");
  50. petalOverlay.classList.remove("hidden");
  51. }, 2000)
  52. });
  53. // to ensure all images is loaded before starting animation and gimmick
  54. function imageLoading() {
  55. const images = document.querySelectorAll("img");
  56. let loadedCount = 0;
  57. const totalImages = images.length;
  58. images.forEach(image => {
  59. if (image.complete) {
  60. loadedCount++;
  61. } else {
  62. image.addEventListener("load", () => {
  63. loadedCount++;
  64. checkAllImagesLoaded();
  65. });
  66. image.addEventListener("error", () => {
  67. loadedCount++;
  68. checkAllImagesLoaded();
  69. });
  70. }
  71. });
  72. function checkAllImagesLoaded() {
  73. if (loadedCount === totalImages) {
  74. let loading = document.getElementById("loading");
  75. loading.remove();
  76. // parts is intro cover
  77. let parts = document.getElementsByClassName("part");
  78. for (let part of parts) {
  79. part.classList.remove("hidden")
  80. }
  81. let pointer = document.getElementById("pointer")
  82. setTimeout(() => {
  83. pointer.classList.remove("hidden")
  84. }, 1500);
  85. }
  86. }
  87. //somehow the server work so fast, script doesn't have much time to set the load eventlistener
  88. //thus we check here, to ensure checkAllImagesLoaded run
  89. checkAllImagesLoaded();
  90. }
  91. // enable open close cover
  92. function scrollOpenCover() {
  93. var partLeftPos = 0;
  94. var partRightPos = 0;
  95. function updatePositions() {
  96. var distance = $(window).scrollTop() * 2;
  97. var left = partLeftPos - distance;
  98. var right = partRightPos - distance;
  99. $('.left').css('left', left + "px");
  100. $('.right').css('right', right + "px");
  101. //Calculate boundaries
  102. var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
  103. //Check if both parts are completely off-screen
  104. var isLeftOffScreen = leftPartRightEdge <= 0;
  105. //Toggle visibility and z-index
  106. if (isLeftOffScreen && left < 0) {
  107. $('.parent').removeClass('z-30');
  108. } else {
  109. $('.parent').addClass('z-30');
  110. }
  111. }
  112. //Initial positions update
  113. updatePositions();
  114. //Listen to scroll events using requestAnimationFrame for smooth animation
  115. var ticking = false;
  116. $(window).scroll(function () {
  117. if (!ticking) {
  118. window.requestAnimationFrame(function () {
  119. updatePositions();
  120. ticking = false;
  121. });
  122. }
  123. ticking = true;
  124. });
  125. }
  126. function reset() {
  127. // reset to top
  128. let body = document.querySelector("body");
  129. window.scrollTo(0, document.body.scrollHeight * 0.05);
  130. body.classList.add("no-scroll");
  131. }
  132. function playMusic() {
  133. var audioElement = document.getElementById('player');
  134. var hasPlayed = false;
  135. if (!hasPlayed) {
  136. console.log('play')
  137. var playPromise = audioElement.play();
  138. if (playPromise !== undefined) {
  139. playPromise.then(function () {
  140. // Automatic playback started!
  141. hasPlayed = true; // Prevent further attempts to play
  142. }).catch(function (error) {
  143. // Automatic playback failed.
  144. console.log('Autoplay failed: ' + error);
  145. });
  146. }
  147. }
  148. }
  149. function eventCountdown() {
  150. //Countdown date (adjust this date to your desired countdown target)
  151. const countdownDate = new Date('2024-08-17T11:00:00').getTime();
  152. //Update the countdown every second
  153. const countdownElement = document.getElementById('countdown');
  154. const countdownTimer = setInterval(() => {
  155. //Get the current date and time
  156. const now = new Date().getTime();
  157. //Calculate the time remaining
  158. const distance = countdownDate - now;
  159. //Calculate days, hours, minutes, and seconds
  160. const days = Math.floor(distance / (1000 * 60 * 60 * 24));
  161. const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  162. const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  163. const seconds = Math.floor((distance % (1000 * 60)) / 1000);
  164. //Format the countdown into a string
  165. const countdownHTML = `
  166. <div class="flex flex-col">
  167. <div class="flex gap-8 justify-center">
  168. <div class="font-medium text-gray-500">${days}</div>
  169. <div class="font-medium text-gray-500">:</div>
  170. <div class="font-medium text-gray-500">${hours.toString().padStart(2, '0')}</div>
  171. <div class="font-medium text-gray-500">:</div>
  172. <div class="font-medium text-gray-500">${minutes.toString().padStart(2, '0')}</div>
  173. <div class="font-medium text-gray-500">:</div>
  174. <div class="font-medium text-gray-500">${seconds.toString().padStart(2, '0')}</div>
  175. </div>
  176. <div class="flex gap-14 justify-center">
  177. <div class="font-medium text-gray-600">Hari</div>
  178. <div class="font-medium text-gray-600">Jam</div>
  179. <div class="font-medium text-gray-600">Minit</div>
  180. <div class="font-medium text-gray-600">Saat</div>
  181. </div>
  182. </div>
  183. `;
  184. //Display the countdown in the element
  185. countdownElement.innerHTML = countdownHTML;
  186. //If the countdown is over, clear the timer and display a message
  187. if (distance < 0) {
  188. clearInterval(countdownTimer);
  189. countdownElement.innerHTML = 'Majlis berlangsung';
  190. }
  191. }, 1000); // Update every second (1000 milliseconds)
  192. }
  193. const observerOptions = {
  194. root: null,
  195. rootMargin: '0px',
  196. threshold: 0.1
  197. };
  198. const observer = new IntersectionObserver((entries, observer) => {
  199. entries.forEach(entry => {
  200. if (entry.isIntersecting) {
  201. entry.target.classList.add('fade-in');
  202. observer.unobserve(entry.target);
  203. }
  204. });
  205. }, observerOptions);
  206. document.querySelectorAll('.fade-element').forEach(element => {
  207. observer.observe(element);
  208. });