Wedding Invitation
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

app.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import './bootstrap';
  2. // 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. $(function() {
  47. var partLeftPos = 0;
  48. var partRightPos = 0;
  49. function updatePositions() {
  50. var distance = $(window).scrollTop() * 2;
  51. var left = partLeftPos - distance;
  52. var right = partRightPos - distance;
  53. $('.left').css('left', left + "px");
  54. $('.right').css('right', right + "px");
  55. // Calculate boundaries
  56. var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
  57. // Check if both parts are completely off-screen
  58. var isLeftOffScreen = leftPartRightEdge <= 0;
  59. // Toggle visibility and z-index
  60. if (isLeftOffScreen && left < 0) {
  61. $('.parent').addClass('fixed');
  62. $('.parent').removeClass('absolute');
  63. $('.parent').removeClass('z-30');
  64. } else {
  65. $('.parent').addClass('absolute');
  66. $('.parent').removeClass('fixed');
  67. $('.parent').addClass('z-30');
  68. }
  69. }
  70. // Initial positions update
  71. updatePositions();
  72. // Listen to scroll events using requestAnimationFrame for smooth animation
  73. var ticking = false;
  74. $(window).scroll(function() {
  75. if (!ticking) {
  76. window.requestAnimationFrame(function() {
  77. updatePositions();
  78. ticking = false;
  79. });
  80. }
  81. ticking = true;
  82. });
  83. });
  84. document.addEventListener('click', function () {
  85. setTimeout(function () {
  86. document.getElementById('petalOverlay').style.display = 'block';
  87. }, 1000); // Delay of 1 second (1000 milliseconds)
  88. });
  89. document.addEventListener('DOMContentLoaded', function() {
  90. var audioElement = document.getElementById('player');
  91. var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
  92. var scrollCount = 0;
  93. var maxScrolls = 8;
  94. var scrollInterval = 200; // Time in milliseconds between each scroll
  95. var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
  96. function playAudio() {
  97. if (!hasPlayed) {
  98. console.log('play')
  99. var playPromise = audioElement.play();
  100. if (playPromise !== undefined) {
  101. playPromise.then(function() {
  102. // Automatic playback started!
  103. hasPlayed = true; // Prevent further attempts to play
  104. }).catch(function(error) {
  105. // Automatic playback failed.
  106. console.log('Autoplay failed: ' + error);
  107. });
  108. }
  109. }
  110. }
  111. function smoothScroll() {
  112. if (!hasPlayed) {
  113. playAudio();
  114. scrollCount++;
  115. if (scrollCount >= maxScrolls) {
  116. playAudio();
  117. } else {
  118. var start = window.pageYOffset;
  119. var target = start + scrollAmount;
  120. // Set duration based on screen size
  121. var screenWidth = window.innerWidth;
  122. var duration;
  123. if (screenWidth < 600) {
  124. duration = 5000; // Smaller screen
  125. } else if (screenWidth < 1200) {
  126. duration = 12000; // Medium screen
  127. } else {
  128. duration = 15000; // Larger screen
  129. }
  130. var startTime = null;
  131. function scrollStep(timestamp) {
  132. if (!startTime) startTime = timestamp;
  133. var progress = timestamp - startTime;
  134. var currentPosition = start + ((target - start) * (progress / duration));
  135. window.scrollTo(0, currentPosition);
  136. if (progress < duration) {
  137. requestAnimationFrame(scrollStep);
  138. } else {
  139. setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
  140. }
  141. }
  142. requestAnimationFrame(scrollStep);
  143. }
  144. }
  145. }
  146. function playOnly() {
  147. if (!hasPlayed) {
  148. playAudio();
  149. scrollCount++;
  150. if (scrollCount >= maxScrolls) {
  151. playAudio();
  152. } else {
  153. setTimeout(playOnly, scrollInterval);
  154. }
  155. }
  156. }
  157. function handleInteraction() {
  158. document.body.classList.remove('no-scroll'); // Enable scrolling
  159. setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
  160. }
  161. // Listen for click or touch event to start auto-scrolling
  162. window.addEventListener('click', handleInteraction);
  163. window.addEventListener('scroll', function() {
  164. if (window.pageYOffset === 0) {
  165. audioElement.pause();
  166. document.getElementById('petalOverlay').style.display = 'none';
  167. hasPlayed = false; // Reset to allow replay
  168. document.body.classList.add('no-scroll');
  169. }
  170. });
  171. // Intersection Observer for fading in elements
  172. const observerOptions = {
  173. root: null,
  174. rootMargin: '0px',
  175. threshold: 0.1
  176. };
  177. const observer = new IntersectionObserver((entries, observer) => {
  178. entries.forEach(entry => {
  179. if (entry.isIntersecting) {
  180. entry.target.classList.add('fade-in');
  181. observer.unobserve(entry.target);
  182. }
  183. });
  184. }, observerOptions);
  185. document.querySelectorAll('.fade-element').forEach(element => {
  186. observer.observe(element);
  187. });
  188. });