Wedding Invitation
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

app.js 7.5KB

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